如何解决“此编码器仅对采用NSSecureCoding的对象进行编码(对象属于'_SwiftValue'类)。”从Crashlytics崩溃

时间:2019-02-19 09:09:39

标签: ios swift

上次更新我们的应用程序后,我遇到了崩溃的问题:

-[NSXPCEncoder _checkObject:]: This coder only encodes objects that adopt NSSecureCoding (object is of class '_SwiftValue').

我试图删除我在此更新中添加的库,但没有帮助。奇怪的是,它仅在iOS 12上崩溃。我们从iOS 9开始支持。我无法重现崩溃。

Crashlytic log:

Fatal Exception: NSInvalidArgumentException
*** -[NSXPCEncoder _checkObject:]: This coder only encodes objects that adopt NSSecureCoding (object is of class '_SwiftValue').

Fatal Exception: NSInvalidArgumentException
0  CoreFoundation                 0x22fea9ea4 __exceptionPreprocess
1  libobjc.A.dylib                0x22f079a50 objc_exception_throw
2  CoreFoundation                 0x22fdb0484 -[NSCache init]
3  Foundation                     0x2308398a0 -[NSXPCEncoder _checkObject:]
4  Foundation                     0x2308395e0 -[NSXPCEncoder _encodeUnkeyedObject:]
5  Foundation                     0x23083a27c -[NSXPCEncoder _encodeArrayOfObjects:forKey:]
6  Foundation                     0x230839b78 -[NSXPCEncoder _encodeObject:]
7  Foundation                     0x23083a27c -[NSXPCEncoder _encodeArrayOfObjects:forKey:]
8  Foundation                     0x230868ed8 -    [NSDictionary(NSDictionary) encodeWithCoder:]
9  Foundation                     0x230839b78 -[NSXPCEncoder _encodeObject:]
10 Foundation                     0x23083a27c -[NSXPCEncoder _encodeArrayOfObjects:forKey:]
11 Foundation                     0x230839b78 -[NSXPCEncoder _encodeObject:]
12 Foundation                     0x23083a27c -[NSXPCEncoder _encodeArrayOfObjects:forKey:]
13 Foundation                     0x230868ed8 -[NSDictionary(NSDictionary) encodeWithCoder:]
14 Foundation                     0x230839b78 -[NSXPCEncoder _encodeObject:]
15 Foundation                     0x23083a27c -[NSXPCEncoder _encodeArrayOfObjects:forKey:]
16 Foundation                     0x230868ed8 -[NSDictionary(NSDictionary) encodeWithCoder:]
17 Foundation                     0x230839b78 -[NSXPCEncoder _encodeObject:]
18 UserNotifications              0x23a3658cc -[UNNotificationContent encodeWithCoder:]
19 Foundation                     0x230839b78 -[NSXPCEncoder _encodeObject:]
20 UserNotifications              0x23a359578 -[UNNotificationRequest encodeWithCoder:]
21 Foundation                     0x230839b78 -[NSXPCEncoder _encodeObject:]
22 Foundation                     0x230a97ed8 _NSXPCSerializationAddInvocationWithOnlyObjectArgumentsArray
23 Foundation                     0x2308369c0 -[NSXPCEncoder _encodeInvocationObjectArgumentsOnly:count:typeString:selector:isReply:into:]
24 Foundation                     0x230836170 -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:]
25 Foundation                     0x230865f3c -[NSXPCConnection _sendSelector:withProxy:arg1:arg2:arg3:]
26 Foundation                     0x230a74ab8 _NSXPCDistantObjectSimpleMessageSend3
27 UserNotifications              0x23a36dbf8 __104-[UNUserNotificationServiceConnection addNotificationRequest:forBundleIdentifier:withCompletionHandler:]_block_invoke
28 libdispatch.dylib              0x22f8e16c8 _dispatch_call_block_and_release
29 libdispatch.dylib              0x22f8e2484 _dispatch_client_callout
30 libdispatch.dylib              0x22f889bd0 _dispatch_lane_serial_drain$VARIANT$mp
31 libdispatch.dylib              0x22f88a74c _dispatch_lane_invoke$VARIANT$mp
32 libdispatch.dylib              0x22f892eb8 _dispatch_workloop_worker_thread
33 libsystem_pthread.dylib        0x22fac50dc _pthread_wqthread
34 libsystem_pthread.dylib        0x22fac7cec start_wqthread

1 个答案:

答案 0 :(得分:1)

遇到相同的问题后,我发现原因是当您尝试在userInfo中放置某些内容时,它必须符合NSSecureCoding。错误消息中已说明,但含义是:

  

此词典中的键必须是属性列表类型,也就是说,它们必须是可以序列化为属性列表格式的类型。

话虽如此,但值得一提的是这些类型:

  

数组,字典,字符串,数据,日期,数字(整数/浮点数),布尔值

我为自己找到的解决方案是将对象存储为Data,然后传递到userInfo