I have made the ExtensionDelegate my UNUserNotificationCenterDelegate and properly assigned it. I have my watchOS 3 app add a notification request, which triggers
userNotificationCenter:willPresentNotification:withCompletionHandler:
I have implemented the method as follows:
- (void) userNotificationCenter:(UNUserNotificationCenter*)center
willPresentNotification:(UNNotification*)notification
withCompletionHandler:(void(^)(UNNotificationPresentationOptions))completionHandler
{
NSLog(@"ExtensionDelegate: willPresent!");
completionHandler(UNNotificationPresentationOptionAlert);
}
The problem is that nothing happens. I'm debugging in Xcode 8.2 on a device running watchOS 3.1, and though this delegate method is triggered, and I can hit the breakpoint, no alert is shown. My content is as follows:
UNMutableNotificationContent* content = [[UNMutableNotificationContent alloc] init];
content.title = notificationType;
content.subtitle = [NSString stringWithFormat:@"Subtitle: %@", notificationType];
content.body = alertTitle;
content.badge = @1;
content.sound = [UNNotificationSound defaultSound];
content.launchImageName = @"LaunchImage";
content.userInfo = @{
@"notificationType" : notificationType,
@"count" : @(count)
};
content.attachments = @[];
content.categoryIdentifier = notificationType;
where notificationType is the NSString I set on my application's launch as follows:
// Register custom notification types
UNNotificationCategory* cat1 = [UNNotificationCategory categoryWithIdentifier:@"Category1"
actions:@[dismissAction]
intentIdentifiers:@[]
options:UNNotificationCategoryOptionNone];
UNNotificationCategory* cat2 = [UNNotificationCategory categoryWithIdentifier:@"Category2"
actions:@[dismissAction, yesAction]
intentIdentifiers:@[]
options:UNNotificationCategoryOptionNone];
NSSet* categorySet = [NSSet setWithArray:@[cat1, cat2]];
[center setNotificationCategories:categorySet];
Unfortunately, when the notification request is made, willPresentNotification comes and goes, the completionHandler gets called, and then the app just keeps on running in the foreground. No notification alert appears on screen. It doesn't appear in the drag-down dock on the watch face, either. What else do I need to do to have it appear, either on-screen then and there, or into the pull-down dock?
Here is a visual example of what I'd expect to see on top of the app, or flush-top with the the top of the screen,with the app running below it. The banner can be even thinner than shown here: