customDismissAction not working for remote notifications

Viewed 852

I'm attempting to tracking push notification opens and dismissals with a custom analytics system on iOS and I have been unable to get any UNNotificationDismissActionIdentifier responses to come through.

My code that registers with the notification center:

if([[[UIDevice currentDevice] systemVersion] integerValue] >= 10){
    UNNotificationCategory* generalCategory = [UNNotificationCategory
                                               categoryWithIdentifier:@"GENERAL"
                                               actions:@[]
                                               intentIdentifiers:@[]
                                               options:UNNotificationCategoryOptionCustomDismissAction];

    // Register the notification categories.
    UNUserNotificationCenter* center = [UNUserNotificationCenter currentNotificationCenter];
    [center setNotificationCategories:[NSSet setWithObjects:generalCategory, nil]];
    [center setDelegate:self];
};

When I send my push notification, I set the category to GENERAL. When I receive the notification and swipe right to dismiss it, I don't receive any delegate callbacks.

Does customDismissAction only work for local notifications?

1 Answers

Ran into the same issue. The documentation mentions that this needs to be part of your APS payload for the remote notification. I had to read over it quite a bit before I found/picked up on it. Make sure to add whatever category you want to the push payload and have it match when registering the dismiss action. So if you used the example "GENERAL", the payload should include that category

"aps" : {
  "category" : "GENERAL",
  "alert" : {
     "body" : "Some message",
  },
  etc...
}
Related