I have my Watch app reacting to receiving localNotifications in my extension delegate's
- (void)didReceiveLocalNotification:(UILocalNotification *)notification
as follows
WKAlertAction *okAction = [WKAlertAction actionWithTitle:@"OK" style:WKAlertActionStyleCancel handler:^(void) {
DbgLog(@"Dismissed notification alert ");
}];
NSArray *alertActions = @[okAction];
assert(extension.rootInterfaceController);
[extension.rootInterfaceController presentAlertControllerWithTitle:notification.alertTitle message:notification.alertBody preferredStyle:WKAlertControllerStyleAlert actions:alertActions];
Which works. Local notifications firing from my app appear on my watch as the alert if the watch app is in focus, just like how they do on the iPhone if the iPhone app is in focus. Falling back to the system notification handling if the watch app isn't in focus or its screen is not currently powered up.
The problem is that these local notifications can appear in relatively quick succession. When they do this, the same code is called and nothing is presented.. You cannot present another alert controller on top of the current one, not saying i want to but I don't think you can dismiss the current alert to then be able to present the new one.
On iOS there were similar problems but you could get round them by using the right view controller to present the new one using something like this
- (UIViewController *)myVisibleViewController
{
if ([self isKindOfClass:[UINavigationController class]])
{
return [[(UINavigationController*)self topViewController] myVisibleViewController];
}
if ([self isKindOfClass:[UITabBarController class]])
{
return [[(UITabBarController *)self selectedViewController] myVisibleViewController];
}
if (self.presentedViewController == nil || self.presentedViewController.isBeingDismissed)
{
return self;
}
return [self.presentedViewController myVisibleViewController];
}
WatchOS however doesn't seem to offer such abilities. Meaning my app cannot really handle notifications as well as i'd like. If anything I'd prefer to just always have the system handle the notifications the way it does when the app's not in focus or if the watch screen is off. But I don't think there's a way you can get this behaviour whilst your app is in focus.
To be honest even the system notifications I find a little flaky if a lot of notifications arrive at once, i don't think the system handles it very well at all and its often the reason that I'll miss some notifications hidden behind others and not properly being shown to the user, something i hope Apple fixes in subsequent WatchOS versions.
Anyone got any ideas, or is it just impossible to have a WatchOS 2 app handle notifications that overlap in presentation timing?
Cheers!