When you register the device for notifications you do it with a UIUserNotificationSettings:
[[UIApplication sharedApplication] registerUserNotificationSettings:[self createUserNotificationSettings]];
For instance, in this method you can create the UIUserNotificationAction which are the action buttons and custom settings:
- (UIUserNotificationSettings *) createUserNotificationSettings {
UIMutableUserNotificationAction *action1 = [[UIMutableUserNotificationAction alloc] init];
[action1 setActivationMode: UIUserNotificationActivationModeForeground];
[action1 setTitle:@"Title1"];
[action1 setIdentifier:@"first_button"];
[action1 setDestructive:YES];
[action1 setAuthenticationRequired:NO];
UIMutableUserNotificationAction *action2 = [[UIMutableUserNotificationAction alloc] init];
[action2 setActivationMode: UIUserNotificationActivationModeForeground];
[action2 setTitle:@"Title2"];
[action2 setIdentifier:@"second_button"];
[action2 setDestructive:NO];
[action2 setAuthenticationRequired:NO];
UIMutableUserNotificationCategory *actionCategory = [[UIMutableUserNotificationCategory alloc] init];
[actionCategory setIdentifier:@"ACTIONABLE"];
[actionCategory setActions:@[action1, action2]
forContext:UIUserNotificationActionContextDefault];
NSSet *categories = [NSSet setWithObject:actionCategory];
UIUserNotificationType types = (UIUserNotificationTypeAlert|
UIUserNotificationTypeSound|
UIUserNotificationTypeBadge);
return [UIUserNotificationSettings settingsForTypes:types categories:categories];
}
When you receive the notification the following method gets called and you can check which button was pressed:
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)notification completionHandler: (void (^)())completionHandler {
if ([identifier isEqualToString: @"first_button"]) {
NSLog(@"First notification button was pressed");
} else {
NSLog(@"Second notification button was pressed");
}
}