iOS Interactive Push

Among other improvements and changes that come along in iOS 8+, Apple introduced interactive notifications that let you take actions on push notifications right from the notification banner or alert without losing focus from the app you’re in at the moment.

Pushwoosh has recently added so-called iOS Categories that allow you to create custom push buttons right from your Pushwoosh Control Panel.

Creating Categories in Pushwoosh Control Panel

  1. First of all, you should create a Category in your Pushwoosh Control Panel. A category contains either one or two buttons.
  2. Open a Configure page of your application in Pushwoosh, and click the Edit Actions button.
  3. Give a name to the Category you are about to create, you will use it for your further reference.
  4. Specify the text which will be used as a button label. iOS displays up to 2 lines of text.
  5. Select a button type:
    • Destructive – the button is red, signifies actions such as delete, reject, dismiss, etc.
    • Non-destructive – the button is blue, signifies positive actions.
  6. Choose whether you would like your app to be launched in the foreground when a user taps on the button by enabling the “Launch app on action” checkbox.
  7. Click “Save changes”, and it will be saved in Pushwoosh with a Category ID.

API

When your application calls registerDevice, Pushwoosh API returns the response that contains a list of available Categories with their IDs and details for each button as follows:

{
  "status_code": 200,
  "status_message": "OK",
  "response": {
    "iosCategories": [
      {
        "categoryId": 65,
        "buttons": [
          {
            "id": 0,
            "label": "Rate",
            "type": "1",
            "startApplication": 1
          },
          {
            "id": 1,
            "label": "Later",
            "type": "0",
            "startApplication": 0
          }
        ]
      }
    ]
  }
}

These Categories are now available on the device, so they can be properly displayed when a message arrives and your application is not running in the foreground.

In order to send your push with a category from the Control Panel, you can simply select it in the iOS platform settings while composing your message. In case you are sending your pushes remotely through Pushwoosh API, in the createMessage requests you should use the "ios_category" parameter with a corresponding Category ID as a value:

 {
        "categoryId": 65,  // Optional. String value. iOS8 category ID from Pushwoosh

When a push message containing a category ID arrives, Pushwoosh SDK displays the notification with a set of buttons this category contains.

Buttons & Actions in Pushwoosh iOS SDK

In order to perform various actions upon opening an app call the following method of the UIApplicationDelegate protocol:

 - (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)notification completionHandler:(void(^)())completionHandler

where identifier is a button ID, and category is derived from the notification payload. Please refer to the sample below:

- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)notification completionHandler:(void(^)())completionHandler {
    NSString *category = notification[@"aps"][@"category"];
     
    if ([category isEqualToString:@"1"]) {
        if ([identifier isEqualToString:@"0"]) {
            //do something
        }
        else if ([identifier isEqualToString:@"1"]) {
            //do something else
        }
    }
    else {
        //handle other category
    }
     
    //must be called when finished
    completionHandler();
}

iOS Interactive Push