xctest and UNUserNotificationCenter = Exception

This is logged as rdar://27768556


Our push notification SDK is migrating to use UNNotificationCenter for iOS 10 deployment targets.


We have extensive unit and integration tests running in the simulator environments.


We'd like to extend our tests to support UNNotificationCenter to generate local notifications for which we can test our SDK code. However, in doing so, even attempting to *access* the -currentNotificationCenter (via [UNUserNotificationCenter currentNotificationCenter]) crashes because xctest is not exposing a bundle identifier.


I've tried swizzling NSBundle (with no success) - UNUserNotificationCenter must be looking for the bundle ID in a way I can't identify.


This tight dependency, and the lack of support for a bundle identifier via xctest, means that automation and unit tests (even to generate local notifications) cannot happen.

Does anyone have any thoughts/tips/hints on this one? Thanks!


Brian M. Criscuolo

Salesforce Marketing Cloud


2016-08-09 13:21:36.308 xctest[24279:7991028] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: bundleIdentifier != nil'
*** First throw call stack:
(
  0   CoreFoundation                      0x0000000101202a0b __exceptionPreprocess + 171
  1   libobjc.A.dylib                     0x0000000100c6421e objc_exception_throw + 48
  2   CoreFoundation                      0x0000000101206b02 +[NSException raise:format:arguments:] + 98
  3   Foundation                          0x00000001007fbd0d -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 195
  4   UserNotifications                   0x0000000106c87b25 -[UNUserNotificationCenter initWithBundleIdentifier:] + 210
  5   UserNotifications                   0x0000000106c877cf __53+[UNUserNotificationCenter currentNotificationCenter]_block_invoke + 106
  6   libdispatch.dylib                   0x0000000103ebf12e _dispatch_client_callout + 8
  7   libdispatch.dylib                   0x0000000103ea9e12 dispatch_once_f + 68
  8   UserNotifications                   0x0000000106c87762 +[UNUserNotificationCenter currentNotificationCenter] + 45

Replies

Hi, bcriscuol.


Did you find a solution for this problem?

Could you please share it?

I would have thought the right approach here is to create a dummy app to host your tests.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Have you resolved the problem:

My code is

if (IOS10DEVICE) {
        UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
        center.delegate = self;
        [center requestAuthorizationWithOptions:(UNAuthorizationOptionAlert | UNAuthorizationOptionBadge | UNAuthorizationOptionSound) completionHandler:^(BOOL granted, NSError * _Nullable error) {
            if (!error && granted) {
                [[UIApplication sharedApplication]registerForRemoteNotifications];
               
            }
        }];
   
    }

and I got the crash:


Invalid parameter not satisfying: bundleIdentifier != nil crash time7

Did you find a solution for this problem?

Could you please share it?

Any update on it?

https://developer.apple.com/library/content/documentation/Miscellaneous/Conceptual/iPhoneOSTechOverview/Introduction/Introduction.html



I can`t open the link ,so can you help me find out the what is the real address? so appreciate that!