You can create interactive notifications by defining action buttons in iOS8.
- Create buttons
UIMutableUserNotificationAction. - Then create
UIMutableUserNotificationCategoryand group actions on the action into categories. - Add all categories to the set.
- Create
UIUserNotificationSettingswith this set of categories. - Register notifications with these settings
- Add a
categoryfield in the push message and send a notification
The following is sample code:
- (void) registerRemoteNotificationWithActions{
UIMutableUserNotificationAction *shareAction = [[UIMutableUserNotificationAction alloc] init];
shareAction.identifier = @"SHARE_IDENTIFIER";
shareAction.title = @"Share";
shareAction.activationMode = UIUserNotificationActivationModeForeground;
shareAction.destructive = NO;
shareAction.authenticationRequired = YES;
UIMutableUserNotificationCategory *shareCategory = [[UIMutableUserNotificationCategory alloc] init];
shareCategory.identifier = @"SHARE_CATEGORY";
[shareCategory setActions:@[shareAction] forContext:UIUserNotificationActionContextDefault];
[shareCategory setActions:@[shareAction] forContext:UIUserNotificationActionContextMinimal];
NSSet *categories = [NSSet setWithObjects:shareCategory, nil];
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}
Example payload format:
{
"aps": {
"badge": 1,
"alert": "Hello world!",
"category": "SHARE_CATEGORY"
}
}
And process the actions using the following method:
- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void(^)())completionHandler
{
if ([identifier isEqualToString:@"SHARE_IDENTIFIER"] ){
}
}
You can check this link for more information.
source
share