I'm aware that after a force quit application:didReceiveRemoteNotification
won't be called (as covered in Will iOS launch my app into the background if it was force-quit by the user?) but I'm also noticing that application:handleActionWithIdentifier:
is also not being called. My interactive notifications are still being displayed to the user but clicking the actions doesn't result in opening the app (like clicking the notification itself would do) or running the code that is defined in application:handleActionWithIdentifier:
. When a user selects the action the notification disappears giving them the impression that everything worked when in fact all they are doing is dismissing the notification. This seems like a pretty poor User Experience so I'd be surprised if iOS continued to present notification actions when no action will be taken. I hope I'm doing something wrong:
//application:didFinishLaunchingWithOptions:
UIMutableUserNotificationAction *action1;
action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode:UIUserNotificationActivationModeBackground];
[action1 setTitle:@"Safe"];
[action1 setIdentifier:NotificationSafeActionIdent];
[action1 setDestructive:NO];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2;
action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode:UIUserNotificationActivationModeBackground];
[action2 setTitle:@"Unsafe"];
[action2 setIdentifier:NotificationUnsafeActionIdent];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory;
actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:NotificationCategoryIdent];
[actionCategory setActions:@[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
UIUserNotificationSettings *settings;
settings = [UIUserNotificationSettings settingsForTypes:types
categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:settings];
//application:handleActionWithIdentifier:
if ([identifier isEqualToString:NotificationSafeActionIdent]) {
// handle safe here including http call
} else if ([identifier isEqualToString:NotificationUnsafeActionIdent]) {
// Handle unsafe here including http call
}
if (completionHandler) {
completionHandler();
}
Am I missing anything or is there no way to call code from the actions if the app has been force quit. If so is there an easy way to prevent the action buttons from being visible in that scenario?