MediaRemote NSInvalidArgumentException

Hello!


I have been experiencing a crash inside of the MediaRemote framework that I can not find much information on. This crash is happing many times everyday, but only for users running iOS 11. The exception is


Fatal Exception: NSInvalidArgumentException

-[NSNull data]: unrecognized selector sent to instance 0x1b233b650


And the full trace of the thread the is crashing is


0 CoreFoundation 0x181789d04 __exceptionPreprocess

1 libobjc.A.dylib 0x1809d8528 objc_exception_throw

2 CoreFoundation 0x1817971c8 __methodDescriptionForSelector

3 CoreFoundation 0x18178f6b0 ___forwarding___

4 CoreFoundation 0x18167501c _CF_forwarding_prep_0

5 MediaRemote 0x18cf8fb08 MRContentItemCreateExternalRepresentation

6 MediaRemote 0x18cf0a5b4 MRCreateDataFromArray

7 MediaRemote 0x18cf0a4d4 MRAddArrayToXPCMessage

8 MediaRemote 0x18cee9c04 _MRServiceHandleGetChildContentItemsMessage

9 libdispatch.dylib 0x18110d088 _dispatch_call_block_and_release

10 libdispatch.dylib 0x18110d048 _dispatch_client_callout

11 libdispatch.dylib 0x181116e48 _dispatch_queue_serial_drain$VARIANT$mp

12 libdispatch.dylib 0x1811177d8 _dispatch_queue_invoke$VARIANT$mp

13 libdispatch.dylib 0x181118200 _dispatch_root_queue_drain_deferred_wlh$VARIANT$mp

14 libdispatch.dylib 0x1811204a0 _dispatch_workloop_worker_thread$VARIANT$mp

15 libsystem_pthread.dylib 0x1813b2fd0 _pthread_wqthread

16 libsystem_pthread.dylib 0x1813b2c20 start_wqthread


It looks like MediaRemote is trying to get underlying data from what it thinks is an array, but in actuallity it is sending the message to an instance of NSNull which does not have a selector called "data". Our app is an audio app which makes use of MPRemoteCommandCenter as well as CarPlay.


Has anyone experienced anything similar or have any insights? Any help would be greatly appreciated!


It's a convention used in some circumstance to put a [NSNull null] object into a NSArray to indicate a missing element (since you can't put a nil into a NSArray). I suspect that's what's happening here, rather the the array itself being a NSNull.


Is there any Swift code involved in creating the array (if the array is something you create, directly or indirectly)? You might get this behavior if Swift thought it was making an array of optionals. IIRC the use of NSNull objects is part of the current bridging mechanism between Swift and Obj-C types.

Thanks for your response! I looked through my code and the only thing I could find close to this is the dictionary that I'm setting for MPNowPlayingInfoCenter.default().nowPlayingInfo may contain some swift optionals set to nil. I'm not sure this is the actual issue since it is a dictionary, but perhaps under the hood the framework is access that dictionary's values as an array or something similar.

MediaRemote NSInvalidArgumentException
 
 
Q