如何修复崩溃"This coder only encodes objects that adopt NSSecureCoding (object is of class '_SwiftValue'



在我们的应用程序的最后更新后,我在崩溃时遇到问题:

-[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

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

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

那样值得一提的是:

数组,字典,字符串,数据,日期,数字(int/float),bool

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

最新更新