You can create interactive notifications by defining the action buttons in iOS8.
- Create
UIMutableUserNotificationAction
buttons.
- Then Create
UIMutableUserNotificationCategory
and group above actions into category.
- Add all categories into set.
- Create
UIUserNotificationSettings
with this category set.
- Register notifications with this settings
- Add
category
field in push payload and send notification
Please find below the sample code:
- (void) registerRemoteNotificationWithActions{
//1. Create action buttons..:)
UIMutableUserNotificationAction *shareAction = [[UIMutableUserNotificationAction alloc] init];
shareAction.identifier = @"SHARE_IDENTIFIER";
shareAction.title = @"Share";
shareAction.activationMode = UIUserNotificationActivationModeForeground;
shareAction.destructive = NO;
shareAction.authenticationRequired = YES;
//2. Then create the category to group actions.:)
UIMutableUserNotificationCategory *shareCategory = [[UIMutableUserNotificationCategory alloc] init];
shareCategory.identifier = @"SHARE_CATEGORY";
[shareCategory setActions:@[shareAction] forContext:UIUserNotificationActionContextDefault];
[shareCategory setActions:@[shareAction] forContext:UIUserNotificationActionContextMinimal];
//3. Then add categories into one set..:)
NSSet *categories = [NSSet setWithObjects:shareCategory, nil];
//4. Finally register remote notification with this action categories..:)
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:categories];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
}
Sample payload format :
{
"aps": {
"badge": 1,
"alert": "Hello world!",
“category”: “SHARE_CATEGORY”
}
}
And handle 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 info.