I want to add a category to my push notification and I can't seem to get any success in my attempts. I tried StackOverflow, but nobody responded, so I'm trying here.
I thought it would be an issue with my Firebase Cloud Functions message payload, but it's not.
I have a function to set a category on my notification when interacted with:
I then call this right before
From, reading many articles, I thought this would work, but my notification just ends up with no actions when i receive it and interact with it.
I even decided to create a UNNotificationServiceExtension, and add the identifier in that, but that didn't work either.
If anybody knows how to do this properly and sees I'm missing something or placing something in the wrong spot, please point it out and let me know, thanks.
I thought it would be an issue with my Firebase Cloud Functions message payload, but it's not.
I have a function to set a category on my notification when interacted with:
Code Block func configureCategory() { let viewAction = UNNotificationAction(identifier: "viewNewEvent", title: "View New Event", options: UNNotificationActionOptions.foreground) let viewCategory = UNNotificationCategory(identifier: "newEventCategory", actions: [viewAction], intentIdentifiers: [], options: []) UNUserNotificationCenter.current().setNotificationCategories(Set([viewCategory])) }
I then call this right before
Code Block application.registerForRemoteNotifications()
From, reading many articles, I thought this would work, but my notification just ends up with no actions when i receive it and interact with it.
I even decided to create a UNNotificationServiceExtension, and add the identifier in that, but that didn't work either.
Code Block override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { self.contentHandler = contentHandler bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) if let bestAttemptContent = bestAttemptContent { bestAttemptContent.title = "\(bestAttemptContent.title) [modified]" bestAttemptContent.categoryIdentifier = "newEventCategory" contentHandler(bestAttemptContent) } }
If anybody knows how to do this properly and sees I'm missing something or placing something in the wrong spot, please point it out and let me know, thanks.