Ios8 setting up interactive push notifications

I am trying to find an updated document that contains any samples of information / code in new interactive push notifications. The manual I found in local and remote push notifications shows that the payload size is 256 bytes. I understand that in ios8 this limit has been increased to 2k.

I am also trying to find documentation on how to add custom buttons to make my ideas interactive. I don't see much in the push notification programming guide.

How to configure a category to add custom buttons with colors? Any documentation on this will be helpful.

+4
source share
2 answers

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{

    //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];

}

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.

+4
source

This is the tutorial I found on youtube for custom action notification. This is done quickly.

https://www.youtube.com/watch?v=Yh3lLpV1k_Y

0

All Articles