Overview

Interactive notifications, when implemented in an application, allows users to add up to three actions in one iOS notification, perform an action based on the notification itself without needing to surface to the foreground, and interact with the notification and not the interface of your mobile application.

Example

If you send a notification and add two actions that allow your users to vote on a specific subject, your app could send the response of the users decision to your Campaign Automation database without having to actually load the user interface and then perform the server update. This creates simple, responsive updates and allows you to collect information from your users.

Requirements

Apple added support for static action categories in iOS 8, it is available for all later iOS versions.

How it works

Interactive notifications are implemented within your app by means of grouping actions into an action category. You create the actions you want to show to your users and add them to a specific category.

here are two types of action categories, static and dynamic. In Static categories actions are created in your app and cannot be changed. This article will describe the use of static categories within your application

To create a static category you need to first specify the actions and labels for your notifications. The following code provides an example of this :


id acceptAction = [[MutableUserNotificationAction alloc] init];
[acceptAction setIdentifier: @"Accept"];
[acceptAction setTitle: @"Accept"];
[acceptAction setActivationMode: UIUserNotificationActivationModeForeground];
[acceptAction setDestructive: false];
[acceptAction setAuthenticationRequired: false];

id rejectAction = [[MutableUserNotificationAction alloc] init];
[rejectAction setIdentifier: @"Reject"];
[rejectAction setTitle: @"Reject"];
[rejectAction setActivationMode: UIUserNotificationActivationModeForeground];
[rejectAction setDestructive: false];
[rejectAction setAuthenticationRequired: false];

Class MutableUserNotificationCategory = NSClassFromString(@"UIMutableUserNotificationCategory");
id category = [[MutableUserNotificationCategory alloc] init];
[category setIdentifier: @"example"];
[category setActions:@[acceptAction, rejectAction] forContext: UIUserNotificationActionContextDefault];
[category setActions:@[acceptAction, rejectAction] forContext: UIUserNotificationActionContextMinimal];
appCategories = [NSSet setWithArray: @[ category ]];

You then need to inform the OS to use the created categories:


UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:[appCategories]];

To handle the user interaction of these notifications you would need to add your implementation to the following method:


- (void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forRemoteNotification:(NSDictionary *)userInfo completionHandler:(void (^)())completionHandler
{
if(userInfo[@"aps"] && [userInfo[@"aps"][@"category"] isEqual: @"example"])
{ // perform action based on user interacting with the example category

Your app now has all that it needs to show the notification to the user as well as perform an action based on the users selection. You now need to send a notification to the user using this category which we have just created. The sample app provided within the SDK has this static category already implemented for you to test.

To add the category to a push notification from your Campaign Automation instance, navigate to Development – Actions. At the bottom of this page you will see the input box for where categories are created. Click the New Category button to add the template to the page. The default category template will be created, you need to modify the ‘category’ key to match to what we have created.

For our example the category would need to look like this.


{
"label": "Example Category implemented in the sample app",
"category": "example",
"description": "Contains the Accept, Reject"

}

If you needed to add extra variables with this push you could use the custom properties sections as shown in the default category template.

Now when you are adding your actions to your iOS app message within the send experience you can select the category you want to use. Select the Add Category button.

You will now be presented with the available categorys you have already created within your Campaign Automation instance. In our case we have the example and invitation categories. We will select the example category.

We also have the option of adding a simple action which will be used if a device does not support these types of notifacations, i.e. those devices running iOS 7 and below.

This message will then be sent to your users when the app receives this message it will display the notifications as created in the static category.

You can also use this category in messages which are sent to the API. To use this category within an API call you can use the following payload:


"aps" : {
"category" : "example",
"alert" : "Message",
"badge" : 3,
"sound" : "default"
}

Join The Discussion

Your email address will not be published. Required fields are marked *