ios - 如何修复 "This coder only encodes objects that adopt NSSecureCoding (object is of class ' _SwiftValue')."来自 Crashlytics 的崩溃

标签 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

最佳答案

遇到同样的问题后,我发现原因是当你试图在 userInfo 中放置一些东西时,它必须符合 NSSecureCoding。错误消息中说明了这一点,但其含义是:

The keys in this dictionary must be property-list types—that is, they must be types that can be serialized into the property-list format.

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

Array, Dictionary, String, Data, Date, Number(Int/Float), Bool

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

关于ios - 如何修复 "This coder only encodes objects that adopt NSSecureCoding (object is of class ' _SwiftValue')."来自 Crashlytics 的崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54762443/

相关文章:

ios - 如何在 CFQuery TableViewController 中为 tableView 设置背景图片

ios - 在应用程序委托(delegate)中显示警报的方法失败,因为它的 rootViewController 不在 View 层次结构中

ios - Swift:通过保存在 Firebase 中的 URL 显示图像

ios - NSDecimalNumber 占位符泄漏

ios - Cocoapods 总是安装旧的 React (0.11.0)

ios - 在 firebase 问题中手动输入数据

swift - 在 ARKit 3 中从 3D 骨架检索骨骼旋转

objective-c - 我可以在子类中实现协议(protocol)的一个功能吗?

ios - 更新和编辑 CoreData 中的实体

iphone - 确定 UIImageview 上是否有图像