Actionable notifications let you add custom action buttons to the standard iOS push notifications. It also gives the user a quick and easy way to perform relevant tasks in response to a notification.
How to implement Actionable Notifications?
To use actionable notifications with MoEngage SDK, you have to define the actions and group them into categories as shown in the example, and pass them as a parameter while registering for push notifications.
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate{
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//--- Rest of Implementation
//For registering for remote notification
let categories = self.getCategories()
MoEngageSDKMessaging.sharedInstance.registerForRemoteNotification(withCategories: categories, andUserNotificationCenterDelegate: appDelegate)
//--- Rest of Implementation
return true
}
//Example to define categories
//This method gives categories
func getCategories() -> Set<UNNotificationCategory>{
let acceptAction = UNNotificationAction.init(identifier: "ACCEPT_IDENTIFIER", title: "Accept", options: .authenticationRequired)
let declineAction = UNNotificationAction.init(identifier: "DECLINE_IDENTIFIER", title: "Decline", options: .destructive)
let maybeAction = UNNotificationAction.init(identifier: "MAYBE_IDENTIFIER", title: "May Be", options: .foreground)
let inviteCategory = UNNotificationCategory.init(identifier: "INVITE_CATEGORY", actions: [acceptAction,declineAction,maybeAction], intentIdentifiers: [], options: .customDismissAction)
let categoriesSet = Set.init([inviteCategory])
return categoriesSet;
}
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOption
{
---------
NSSet* categories = [self getNotificationCategories];
[[MoEngageSDKMessaging sharedInstance] registerForRemoteNotificationWithCategories:categories andUserNotificationCenterDelegate:self];
}
---------
return YES;
}
//Example to define categories
//This method gives categories
-(NSSet*)getNotificationCategories{
UNNotificationAction *acceptAction = [UNNotificationAction actionWithIdentifier:@"ACCEPT_IDENTIFIER" title:@"Accept" options:UNNotificationActionOptionAuthenticationRequired];
UNNotificationAction *declineAction = [UNNotificationAction actionWithIdentifier:@"DECLINE_IDENTIFIER" title:@"Decline" options:(UNNotificationActionOptionDestructive)];
UNNotificationAction *maybeAction = [UNNotificationAction actionWithIdentifier:@"MAYBE_IDENTIFIER" title:@"May Be" options:UNNotificationActionOptionNone];
UNNotificationCategory* inviteCategory = [UNNotificationCategory categoryWithIdentifier:@"INVITE_CATEGORY"actions:@[acceptAction,maybeAction, declineAction,opt4Action] intentIdentifiers:@[] options:UNNotificationCategoryOptionNone];
NSSet *categories = [NSSet setWithObjects:inviteCategory,nil];
return categories;
}
As you can see in the example Accept, Decline, and May Be actions are grouped to a category i.e,"INVITE_CATEGORY".
info |
Notification Categories MoEngage recommended not to change the actions grouped in a category across the app versions, as it will lead to users seeing different actions for the same category across different app versions. |