objective-ccrashios11unusernotificationcenter

iOS 11 crashing with bundleProxy != nil error on using UNUserNotificationCenter


The following line of code is where our app has suddenly started to crash on iOS 11 / 11.0.1 / 11.0.2 / 11.1.1 / 11.2.2 for some users:

UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];

We've got this in didFinishLaunchingWithOptions. The crash report says:

Fatal Exception: NSInternalInconsistencyException
Invalid parameter not satisfying: bundleProxy != nil

Fatal Exception: NSInternalInconsistencyException
0  CoreFoundation                 0x1869b3d38 __exceptionPreprocess
1  libobjc.A.dylib                0x185ec8528 objc_exception_throw
2  CoreFoundation                 0x1869b3c0c +[NSException raise:format:]
3  Foundation                     0x187342c24 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:]
4  UserNotifications              0x18fcc973c -[UNUserNotificationCenter initWithBundleProxy:]
5  UserNotifications              0x18fcc950c __53+[UNUserNotificationCenter currentNotificationCenter]_block_invoke
6  libdispatch.dylib              0x186339048 _dispatch_client_callout
7  libdispatch.dylib              0x18633c710 dispatch_once_f$VARIANT$mp
8  UserNotifications              0x18fcc94ac +[UNUserNotificationCenter currentNotificationCenter]

It's coming from iOS clearly. Any one else experiencing the same error? Any idea what's going on?


Solution

  • I'm not sure if this is going to work for everyone, however I've figured it out for my use case. I had created a framework that the iOS app used. This framework was using UNUserNotificationCenter to setup alerts. It seems for some reason, the 'bundle' does not get correctly initialised when this code is used from inside a framework. Sometimes it works, sometimes it doesn't. This bundleProxy, by the sound of things, is some kind of a proxy that the notification framework relies on. Since the code is executing from inside of a framework, perhaps this bundle is not found at runtime and the system returns nil. I've had this issue in general when trying to load resources from the Framework where the bundle location isn't correct.

    Any way, the solution for me was to store a reference to [UNUserNotificationCenter currentNotificationCenter] in the app's delegate at launch, and then pass this to any method that wanted to use it. By the time the app has finished launching, this proxy seems to load correctly if the calling code is the app's binary itself. This seems to have fixed it for me.