4

I'm trying to find an updated doc that includes any info / code samples on the new interactive push notifications. The guide I found on Local & Remote Push Notifications still shows the payload size is 256 bytes. My understanding is that in ios8 that limit has been raised to 2k.

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

How do I setup a category to add custom buttons with colors? Any documentation on this would be useful.

samonderous
  • 649
  • 1
  • 10
  • 22
  • Refer this link http://stackoverflow.com/questions/25929665/features-supported-by-ios8-interactive-notification/25930069#25930069 – Sourav Gupta Sep 19 '14 at 09:11

2 Answers2

4

You can create interactive notifications by defining the action buttons in iOS8.

  1. Create UIMutableUserNotificationAction buttons.
  2. Then Create UIMutableUserNotificationCategory and group above actions into category.
  3. Add all categories into set.
  4. Create UIUserNotificationSettings with this category set.
  5. Register notifications with this settings
  6. 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.

christijk
  • 1,753
  • 18
  • 26
0

This is a tutorial I found in youtube for custom action push notification. It is done in swift.

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

bitsandgates
  • 315
  • 1
  • 3
  • 7