iosapple-push-notificationsunnotificationscontentextension

UNNotificationAction sometimes not showing in remote notification


I have registered the UNNotificationAction's in appdelegate with the identifier, also i have added that identifier in info.plist in notification extension. Buttons are visible if i install the app, after killing the app buttons are not visible. Also i have cross checked with the category identifier. Its working fine in sample application but the behaviour is weird when i integrate it in the app.

    UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
    UNNotificationAction *action = [UNNotificationAction actionWithIdentifier:@"next"
                                                                        title:actionTitle1
                                                                      options:UNNotificationActionOptionNone];
    UNNotificationAction *action2 = [UNNotificationAction actionWithIdentifier:@"goto"
                                                                         title:actionTitle2
                                                                       options:UNNotificationActionOptionNone];
    UNNotificationCategory *category = [UNNotificationCategory categoryWithIdentifier:@"category_identifier"
                                                                              actions:@[action,action2] intentIdentifiers:@[]
                                                                              options:UNNotificationCategoryOptionNone];
    NSSet *categories = [NSSet setWithObject:category];
    [center setNotificationCategories:categories];

Solution

  • I am calling setNotificationCategories multiple times, that's the reason UNNotificationAction not getting displayed.