简体   繁体   English

苹果因崩溃而拒绝应用程序,无法重现它

[英]Apple rejected App due to crash, can't reproduce it

Hello guys and thank you in advance for any tip/help.大家好,提前感谢您的任何提示/帮助。

I really need some help with a crash log from apple that has been bugging me for the last week, i sent 4 builds (Built using xCode 11.1) and every time i get the same answer:我真的需要一些帮助来解决上周一直困扰我的苹果崩溃日志,我发送了 4 个版本(使用 xCode 11.1 构建),每次我得到相同的答案:

Guideline 2.1 - Performance - App Completeness指南 2.1 - 性能 - 应用程序完整性

Your app crashed on iPad running iOS 13.5 on WiFi when we logged in with Facebook account.当我们使用 Facebook 帐户登录时,您的应用程序在 iPad 在 WiFi 上运行 iOS 13.5 时崩溃。

Step to reproduce the crash:重现崩溃的步骤:

  1. Launch app启动应用程序
  2. Select “Login with Facebook Select “使用 Facebook 登录
  3. Accept EULA接受 EULA
  4. Tap “Continue” in Facebook login screen在 Facebook 登录屏幕中点击“继续”
  5. App crashes应用程序崩溃

At first i was able to reproduce the crash and this was the xCode crash on my real device using same OS version as Apple:起初我能够重现崩溃,这是我使用与 Apple 相同的操作系统版本在我的真实设备上发生的 xCode 崩溃:

https://imgur.com/a/aKgf2uO https://imgur.com/a/aKgf2uO

Then someone suggested AlamoFire Pod Issue with swift compiler optimization and that i should set Swift Compiler Optimization to no Optimization ( was Optimizing for Speed beforehand ).然后有人建议 swift 编译器优化的 AlamoFire Pod 问题,我应该将 Swift 编译器优化设置为无优化(预先优化速度)。 When i did that it actually fixed the issue and i tested it on multiple real devices.当我这样做时,它实际上解决了问题,我在多个真实设备上对其进行了测试。 Every time i was setting it to Optimize for speed it would crash the same way as Apple reported and every time i would set it to none it would run smoothly, so i sent the build for review with No Optimization on release config and to my surprise they gave me the same answer with the same crash log.每次我将其设置为优化速度时,它都会以与 Apple 报告的方式相同的方式崩溃,并且每次我将其设置为无时,它都会顺利运行,所以我发送构建以供审核,发布配置上没有优化,令我惊讶的是他们用相同的崩溃日志给了我相同的答案。

Here is the crash Log From Apple这是来自 Apple 的崩溃日志

{"app_name":"myApp","timestamp":"2020-06-29 10:04:19.00 -0700","app_version":"1.3.4","slice_uuid":"1b3cb360-baf6-3d14-922f-9a232b3e5d9f","adam_id":1463189126,"build_version":"1.3","bundleID":"com.myApp","share_with_app_devs":0,"is_first_party":0,"bug_type":"109","os_version":"iPhone OS 13.5 (17F75)","incident_id":"C410440D-AA9F-4DB7-9C34-972588AC0651","name":"myApp"}
Incident Identifier: C410440D-AA9F-4DB7-9C34-972588AC0651
CrashReporter Key:   7e4f06e26c34abc3889f779184ac47940952c29e
Hardware Model:      xxx
Process:             myApp [5131]
Path:                /private/var/containers/Bundle/Application/1ACDDEDC-CD75-4F61-9935-42E0D16E6329/myApp.app/myApp
Identifier:          com.myApp
Version:             1.3 (1.3.4)
AppStoreTools:       11E608a
Code Type:           ARM-64 (Native)
Role:                Foreground
Parent Process:      launchd [1]
Coalition:           com.myApp [2138]


Date/Time:           2020-06-29 10:04:19.5937 -0700
Launch Time:         2020-06-29 10:01:43.7505 -0700
OS Version:          iPhone OS 13.5 (17F75)
Release Type:        User
Baseband Version:    n/a
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Last Exception Backtrace:
0   CoreFoundation                  0x18a0ff794 0x189fd5000 + 1222548
1   libobjc.A.dylib                 0x189e21bcc 0x189e1c000 + 23500
2   CoreFoundation                  0x18a1552dc 0x189fd5000 + 1573596
3   CoreFoundation                  0x18a12b090 0x189fd5000 + 1400976
4   CoreFoundation                  0x18a12b758 0x189fd5000 + 1402712
5   CoreFoundation                  0x18a12b458 0x189fd5000 + 1401944
6   CoreFoundation                  0x18a12b80c 0x189fd5000 + 1402892
7   CoreFoundation                  0x189fdc894 0x189fd5000 + 30868
8   CoreFoundation                  0x18a133840 0x189fd5000 + 1435712
9   CoreFoundation                  0x18a068d24 0x189fd5000 + 605476
10  CoreFoundation                  0x18a0685b8 0x189fd5000 + 603576
11  CoreFoundation                  0x189fd92b8 0x189fd5000 + 17080
12  CoreFoundation                  0x189fdc2f4 0x189fd5000 + 29428
13  CoreFoundation                  0x18a1369d8 0x189fd5000 + 1448408
14  Foundation                      0x18a3fa818 0x18a3b3000 + 292888
15  myApp                       0x1050895c4 static Helper.savePurchasedPlan(data:) + 1463748 (Helper.swift:193)
16  myApp                       0x1055d255c SocialLogin.storeToken(responseData:) + 7005532 (SocialLogin.swift:100)
17  myApp                       0x1055d2e74 closure #1 in SocialLogin.facebookLoginAPI(data:) + 7007860 (SocialLogin.swift:144)
18  myApp                       0x105140798 thunk for @escaping @callee_guaranteed (@guaranteed ResponseModel) -> () + 2213784 (<compiler-generated>:0)
19  RxSwift                         0x1084abb64 closure #1 in ObservableType.subscribe(onNext:onError:onCompleted:onDisposed:) + 342884 (ObservableType+Extensions.swift:65)
20  RxSwift                         0x1084abd64 partial apply for closure #1 in ObservableType.subscribe(onNext:onError:onCompleted:onDisposed:) + 343396 (<compiler-generated>:0)
21  RxSwift                         0x108460e04 AnonymousObserver.onCore(_:) + 36356 (AnonymousObserver.swift:24)
22  RxSwift                         0x1084ae5c0 ObserverBase.on(_:) + 353728 (ObserverBase.swift:18)
23  RxSwift                         0x1084ae77c protocol witness for ObserverType.on(_:) in conformance ObserverBase<A> + 354172 (<compiler-generated>:0)
24  RxSwift                         0x1084aeb8c partial apply + 355212 (<compiler-generated>:0)
25  RxSwift                         0x1084c8898 thunk for @escaping @callee_guaranteed (@in_guaranteed Event<A>) -> () + 460952 (<compiler-generated>:0)
26  RxSwift                         0x1084b4ed4 PublishSubject.on(_:) + 380628 (Bag+Rx.swift:14)
27  RxSwift                         0x1084b6104 protocol witness for ObserverType.on(_:) in conformance PublishSubject<A> + 385284 (<compiler-generated>:0)
28  RxSwift                         0x1084ae920 ObserverType.onNext(_:) + 354592 (ObserverType.swift:27)
29  myApp                       0x1057acedc closure #1 in Authentication.requestAPI(requestData:apiName:) + 8949468 (Authentication.swift:149)
30  myApp                       0x1057ab510 thunk for @escaping @callee_guaranteed (@guaranteed NSHTTPURLResponse, @in_guaranteed Any) -> () + 8942864 (<compiler-generated>:0)
31  RxSwift                         0x1084abb64 closure #1 in ObservableType.subscribe(onNext:onError:onCompleted:onDisposed:) + 342884 (ObservableType+Extensions.swift:65)
32  RxSwift                         0x1084abd64 partial apply for closure #1 in ObservableType.subscribe(onNext:onError:onCompleted:onDisposed:) + 343396 (<compiler-generated>:0)
33  RxSwift                         0x108460e04 AnonymousObserver.onCore(_:) + 36356 (AnonymousObserver.swift:24)
34  RxSwift                         0x1084ae5c0 ObserverBase.on(_:) + 353728 (ObserverBase.swift:18)
35  RxSwift                         0x1084ae77c protocol witness for ObserverType.on(_:) in conformance ObserverBase<A> + 354172 (<compiler-generated>:0)
36  RxSwift                         0x1084ce4ec Sink.forwardOn(_:) + 484588 (Sink.swift:34)
37  RxSwift                         0x10848c6b8 DebugSink.on(_:) + 214712 (Debug.swift:61)
38  RxSwift                         0x10848c81c protocol witness for ObserverType.on(_:) in conformance DebugSink<A, B> + 215068 (<compiler-generated>:0)
39  RxSwift                         0x1084ce4ec Sink.forwardOn(_:) + 484588 (Sink.swift:34)
40  RxSwift                         0x1084a6ee8 MergeSinkIter.on(_:) + 323304 (Merge.swift:394)
41  RxSwift                         0x1084a706c protocol witness for ObserverType.on(_:) in conformance MergeSinkIter<A, B, C> + 323692 (<compiler-generated>:0)
42  RxSwift                         0x1084ce4ec Sink.forwardOn(_:) + 484588 (Sink.swift:34)
43  RxSwift                         0x10848929c AnonymousObservableSink.on(_:) + 201372 (Create.swift:50)
44  RxSwift                         0x1084894b0 protocol witness for ObserverType.on(_:) in conformance AnonymousObservableSink<A> + 201904 (<compiler-generated>:0)
45  RxSwift                         0x1084aeb8c partial apply + 355212 (<compiler-generated>:0)
46  RxSwift                         0x108460f00 AnyObserver.on(_:) + 36608 (AnyObserver.swift:39)
47  RxAlamofire                     0x10820191c partial apply for specialized + 71964 (<compiler-generated>:0)
48  Alamofire                       0x10791fa80 closure #1 in closure #1 in DataRequest.response<A>(queue:responseSerializer:completionHandler:) + 211584 (ResponseSerialization.swift:167)
49  Alamofire                       0x107903074 thunk for @escaping @callee_guaranteed () -> () + 94324 (<compiler-generated>:0)
50  libdispatch.dylib               0x189dc49a8 0x189d6a000 + 371112
51  libdispatch.dylib               0x189dc5524 0x189d6a000 + 374052
52  libdispatch.dylib               0x189d775b4 0x189d6a000 + 54708
53  CoreFoundation                  0x18a07d7fc 0x189fd5000 + 690172
54  CoreFoundation                  0x18a0786d0 0x189fd5000 + 669392
55  CoreFoundation                  0x18a077ce8 0x189fd5000 + 666856
56  GraphicsServices                0x1941c238c 0x1941bf000 + 13196
57  UIKitCore                       0x18e1a6444 0x18d778000 + 10675268
58  myApp                       0x104f44164 main + 131428 (AppDelegate.swift:39)
59  libdyld.dylib                   0x189eff8f0 0x189efe000 + 6384


Thread 0 name:  Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0   libsystem_kernel.dylib          0x0000000189ef4d88 0x189ecf000 + 155016
1   libsystem_pthread.dylib         0x0000000189e0d1e8 0x189e0b000 + 8680
2   libsystem_c.dylib               0x0000000189d609b0 0x189cee000 + 469424
3   libsystem_c.dylib               0x0000000189d60940 0x189cee000 + 469312
4   libc++abi.dylib                 0x0000000189ec8cc0 0x189eb6000 + 76992
5   libc++abi.dylib                 0x0000000189ebae10 0x189eb6000 + 19984
6   libobjc.A.dylib                 0x0000000189e21e80 0x189e1c000 + 24192
7   myApp                       0x000000010595c0f4 CLSTerminateHandler+ 10715380 () + 344
8   libc++abi.dylib                 0x0000000189ec814c 0x189eb6000 + 74060
9   libc++abi.dylib                 0x0000000189ec80e4 0x189eb6000 + 73956
10  libdispatch.dylib               0x0000000189dc5538 0x189d6a000 + 374072
11  libdispatch.dylib               0x0000000189d775b4 0x189d6a000 + 54708
12  CoreFoundation                  0x000000018a07d7fc 0x189fd5000 + 690172
13  CoreFoundation                  0x000000018a0786d0 0x189fd5000 + 669392
14  CoreFoundation                  0x000000018a077ce8 0x189fd5000 + 666856
15  GraphicsServices                0x00000001941c238c 0x1941bf000 + 13196
16  UIKitCore                       0x000000018e1a6444 0x18d778000 + 10675268
17  myApp                       0x0000000104f44164 main + 131428 (AppDelegate.swift:39)
18  libdyld.dylib                   0x0000000189eff8f0 0x189efe000 + 6384

Thread 1 name:  Dispatch queue: com.apple.libtrace.state.block-list
Thread 1:
0   libsystem_kernel.dylib          0x0000000189ef577c 0x189ecf000 + 157564
1   libdispatch.dylib               0x0000000189d6c0a8 0x189d6a000 + 8360
2   libdispatch.dylib               0x0000000189d6be84 0x189d6a000 + 7812
3   libdispatch.dylib               0x0000000189d7834c 0x189d6a000 + 58188
4   libdispatch.dylib               0x0000000189d77f6c 0x189d6a000 + 57196
5   libsystem_trace.dylib           0x0000000189cb6ab0 0x189ca4000 + 76464
6   libdispatch.dylib               0x0000000189dc49a8 0x189d6a000 + 371112
7   libdispatch.dylib               0x0000000189dc5524 0x189d6a000 + 374052
8   libdispatch.dylib               0x0000000189d718a4 0x189d6a000 + 30884
9   libdispatch.dylib               0x0000000189d722c4 0x189d6a000 + 33476
10  libdispatch.dylib               0x0000000189d7b78c 0x189d6a000 + 71564
11  libsystem_pthread.dylib         0x0000000189e16b74 0x189e0b000 + 47988
12  libsystem_pthread.dylib         0x0000000189e19740 0x189e0b000 + 59200

Thread 2 name:  com.apple.uikit.eventfetch-thread
Thread 2:
0   libsystem_kernel.dylib          0x0000000189ed3198 0x189ecf000 + 16792
1   libsystem_kernel.dylib          0x0000000189ed260c 0x189ecf000 + 13836
2   CoreFoundation                  0x000000018a07d468 0x189fd5000 + 689256
3   CoreFoundation                  0x000000018a07849c 0x189fd5000 + 668828
4   CoreFoundation                  0x000000018a077ce8 0x189fd5000 + 666856
5   Foundation                      0x000000018a3bb01c 0x18a3b3000 + 32796
6   Foundation                      0x000000018a3baefc 0x18a3b3000 + 32508
7   UIKitCore                       0x000000018e2495dc 0x18d778000 + 11343324
8   Foundation                      0x000000018a4e9e20 0x18a3b3000 + 1273376
9   libsystem_pthread.dylib         0x0000000189e15d98 0x189e0b000 + 44440
10  libsystem_pthread.dylib         0x0000000189e1974c 0x189e0b000 + 59212

Thread 3 name:  JavaScriptCore bmalloc scavenger
Thread 3:
0   libsystem_kernel.dylib          0x0000000189ef4b58 0x189ecf000 + 154456
1   libsystem_pthread.dylib         0x0000000189e0ece4 0x189e0b000 + 15588
2   libc++.1.dylib                  0x0000000189f467ac 0x189f3a000 + 51116
3   JavaScriptCore                  0x0000000198feaab8 0x198f61000 + 563896
4   JavaScriptCore                  0x0000000198fee790 0x198f61000 + 579472
5   JavaScriptCore                  0x0000000198fee4a0 0x198f61000 + 578720
6   JavaScriptCore                  0x0000000198fef6e4 0x198f61000 + 583396
7   libsystem_pthread.dylib         0x0000000189e15d98 0x189e0b000 + 44440
8   libsystem_pthread.dylib         0x0000000189e1974c 0x189e0b000 + 59212

Thread 4 name:  com.twitter.crashlytics.ios.MachExceptionServer
Thread 4:
0   libsystem_kernel.dylib          0x0000000189ed3198 0x189ecf000 + 16792
1   libsystem_kernel.dylib          0x0000000189ed260c 0x189ecf000 + 13836
2   myApp                       0x0000000105949374 CLSMachExceptionServer + 100
3   libsystem_pthread.dylib         0x0000000189e15d98 0x189e0b000 + 44440
4   libsystem_pthread.dylib         0x0000000189e1974c 0x189e0b000 + 59212

Thread 5 name:  com.apple.NSURLConnectionLoader
Thread 5:
0   libsystem_kernel.dylib          0x0000000189ed3198 0x189ecf000 + 16792
1   libsystem_kernel.dylib          0x0000000189ed260c 0x189ecf000 + 13836
2   CoreFoundation                  0x000000018a07d468 0x189fd5000 + 689256
3   CoreFoundation                  0x000000018a07849c 0x189fd5000 + 668828
4   CoreFoundation                  0x000000018a077ce8 0x189fd5000 + 666856
5   CFNetwork                       0x000000018d338894 0x18d337000 + 6292
6   Foundation                      0x000000018a4e9e20 0x18a3b3000 + 1273376
7   libsystem_pthread.dylib         0x0000000189e15d98 0x189e0b000 + 44440
8   libsystem_pthread.dylib         0x0000000189e1974c 0x189e0b000 + 59212

Thread 6 name:  WebThread
Thread 6:
0   libsystem_kernel.dylib          0x0000000189ed3198 0x189ecf000 + 16792
1   libsystem_kernel.dylib          0x0000000189ed260c 0x189ecf000 + 13836
2   CoreFoundation                  0x000000018a07d468 0x189fd5000 + 689256
3   CoreFoundation                  0x000000018a07849c 0x189fd5000 + 668828
4   CoreFoundation                  0x000000018a077ce8 0x189fd5000 + 666856
5   WebCore                         0x00000001925f2ac0 0x191c49000 + 10132160
6   libsystem_pthread.dylib         0x0000000189e15d98 0x189e0b000 + 44440
7   libsystem_pthread.dylib         0x0000000189e1974c 0x189e0b000 + 59212

Thread 7 name:  AVAudioSession Notify Thread
Thread 7:
0   libsystem_kernel.dylib          0x0000000189ed3198 0x189ecf000 + 16792
1   libsystem_kernel.dylib          0x0000000189ed260c 0x189ecf000 + 13836
2   CoreFoundation                  0x000000018a07d468 0x189fd5000 + 689256
3   CoreFoundation                  0x000000018a07849c 0x189fd5000 + 668828
4   CoreFoundation                  0x000000018a077ce8 0x189fd5000 + 666856
5   AVFAudio                        0x0000000196e21a2c 0x196dbc000 + 416300
6   AVFAudio                        0x0000000196e727a0 0x196dbc000 + 747424
7   libsystem_pthread.dylib         0x0000000189e15d98 0x189e0b000 + 44440
8   libsystem_pthread.dylib         0x0000000189e1974c 0x189e0b000 + 59212

Thread 8 name:  LocalStorage
Thread 8:
0   libsystem_kernel.dylib          0x0000000189ef4b58 0x189ecf000 + 154456
1   libsystem_pthread.dylib         0x0000000189e0ece4 0x189e0b000 + 15588
2   JavaScriptCore                  0x0000000198faf5fc 0x198f61000 + 321020
3   JavaScriptCore                  0x0000000198f9460c 0x198f61000 + 210444
4   WebKitLegacy                    0x00000001961f6dbc 0x1961c7000 + 196028
5   WebKitLegacy                    0x00000001961f9ff4 0x1961c7000 + 208884
6   WebKitLegacy                    0x00000001961f9550 0x1961c7000 + 206160
7   JavaScriptCore                  0x0000000198facc88 0x198f61000 + 310408
8   JavaScriptCore                  0x0000000198faedc4 0x198f61000 + 318916
9   libsystem_pthread.dylib         0x0000000189e15d98 0x189e0b000 + 44440
10  libsystem_pthread.dylib         0x0000000189e1974c 0x189e0b000 + 59212

Thread 9 name:  com.apple.CFNetwork.CustomProtocols
Thread 9:
0   libsystem_kernel.dylib          0x0000000189ed3198 0x189ecf000 + 16792
1   libsystem_kernel.dylib          0x0000000189ed260c 0x189ecf000 + 13836
2   CoreFoundation                  0x000000018a07d468 0x189fd5000 + 689256
3   CoreFoundation                  0x000000018a07849c 0x189fd5000 + 668828
4   CoreFoundation                  0x000000018a077ce8 0x189fd5000 + 666856
5   CFNetwork                       0x000000018d338894 0x18d337000 + 6292
6   Foundation                      0x000000018a4e9e20 0x18a3b3000 + 1273376
7   libsystem_pthread.dylib         0x0000000189e15d98 0x189e0b000 + 44440
8   libsystem_pthread.dylib         0x0000000189e1974c 0x189e0b000 + 59212

Thread 10:
0   libsystem_pthread.dylib         0x0000000189e19738 0x189e0b000 + 59192

Thread 11:
0   libsystem_pthread.dylib         0x0000000189e19738 0x189e0b000 + 59192

Thread 12:
0   libsystem_pthread.dylib         0x0000000189e19738 0x189e0b000 + 59192

Thread 13:
0   libsystem_pthread.dylib         0x0000000189e19738 0x189e0b000 + 59192

Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x0000000000000000   x5: 0x0000000000989680   x6: 0x000000000000006e   x7: 0xffffffffffffffec
    x8: 0x000000010755d840   x9: 0x141b95868448e1e7  x10: 0x00000000000003e8  x11: 0x000000000000000b
   x12: 0x00000001c3b66080  x13: 0x0000000000000001  x14: 0x0000000000000010  x15: 0x0000000000000004
   x16: 0x0000000000000148  x17: 0x0000000000000000  x18: 0x0000000000000000  x19: 0x0000000000000006
   x20: 0x0000000000000407  x21: 0x000000016aeda5e0  x22: 0x000000010755d920  x23: 0x0000000000000000
   x24: 0x0000000000000114  x25: 0x0000000283ae68c0  x26: 0x000000010755d920  x27: 0x00000000000020ff
   x28: 0x0000000002ffffff   fp: 0x000000016aeda500   lr: 0x0000000189e0d1e8
    sp: 0x000000016aeda4e0   pc: 0x0000000189ef4d88 cpsr: 0x40000000
   esr: 0x56000080  Address size fault

ALSO this is Helper.swift Line 193:这也是 Helper.swift 第 193 行:

class func savePurchasedPlan(data:[String:Any]){
        UserDefaults.standard.setValue(data, forKey: "purchaseDetails") .
        UserDefaults.standard.synchronize()
    }

Line 193 is: UserDefaults.standard.setValue(data, forKey: "purchaseDetails").第 193 行是:UserDefaults.standard.setValue(data, forKey: "purchaseDetails")。

Don't save [String:Any] directly.不要直接保存 [String:Any]。 UserDefaults can only handle basic types like Int and String. UserDefaults 只能处理基本类型,如 Int 和 String。 if you want to save a structure like that, create an object for it (like your purchase plan) and make that object NSObject and NSCoding, after that you can encode and decode the object.如果您想保存这样的结构,请为它创建一个 object(如您的购买计划)并制作 object NSObject 和 NSCoding,之后您可以编码和解码 ZA8CFDE6331BD59EB2AC96F8911C4B666

Example from one of my project:我的一个项目的示例:

import Foundation
class User: NSObject, NSCoding {
    
    let userId: Int
    let accessToken: String
    
    init?(WithValues values: NSDictionary) {
        guard let accessTokenValue = values.value(forKey: "accessToken") as? String else {
            return nil
        }
        
        guard accessTokenValue.count > 0 else {
            return nil
        }
        
        guard let userDictionary = values.value(forKey: "user") as? NSDictionary else {
            return nil
        }
        
        guard let userIdValue = userDictionary.value(forKey: "id") as? Int else {
            return nil
        }
        
        self.accessToken = accessTokenValue
        self.userId = userIdValue
    }
    
    init(WithUserId userId: Int, AccessToken accessToken: String) {
        self.userId = userId
        self.accessToken = accessToken
    }
    
    required convenience init(coder aCoder: NSCoder) {
        let userId = aCoder.decodeInteger(forKey: "userId")
        let accessToken = aCoder.decodeObject(forKey: "accessToken") as? String ?? ""
        self.init(WithUserId: userId, AccessToken: accessToken)
    }
    
    func encode(with acoder: NSCoder) {
        acoder.encode(userId,forKey: "userId")
        acoder.encode(accessToken,forKey: "accessToken")
    }
    
}

Usage:用法:

//Saving
let encoded = NSKeyedArchiver.archivedData(withRootObject: user)
UserDefaults.standard.set(encoded, forKey: "user")

//Loading
if let decoded = UserDefaults.standard.object(forKey: "user") as? Data {
        NSKeyedUnarchiver.setClass(User.self, forClassName: "YourTarget.User")
        
    if let user = NSKeyedUnarchiver.unarchiveObject(with: decoded) as? User {
        _user = user
    } else {
        _user = nil
        //Decoded data is invalid, reset
        UserDefaults.standard.set(nil, forKey: "user")
    }
} else {
    _user = nil
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM