Lifeplus
Lifeplus

Reputation: 581

How to fix "This coder only encodes objects that adopt NSSecureCoding (object is of class '_SwiftValue')." crash from Crashlytics

After last update of our app I had problem with crashing on exeption:

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

I tried to remove library I add in this update, but it didn't help. The strange is, that its crashing only on iOS 12. We are supporting from iOS 9. I am not able to reproduce crash.

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

Upvotes: 6

Views: 5779

Answers (1)

inokey
inokey

Reputation: 6200

After encountering the same issue, I found that reason is that when you try to put something in userInfo it has to conform to NSSecureCoding. That stated in the error message but the implications are that:

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.

With that said it's worth mentioning these types:

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

The solution I found for myself is storing an object as Data and then passing into the userInfo.

Upvotes: 14

Related Questions