I am working on an iOS app based on device to device push notifications. My notifications are working fine when the app is in foreground and background. But it doesn't work as per requirement, when the app is in killed state. I have a custom notification which has two buttons (Accept and Reject). When the app is in killed state, I am able to get the notification, but cannot perform action on buttons. But when the app is in foreground or background, it works perfectly. Can you guys please help me this? I am stuck in this for long now.
Note: I am using FCM to generate push notifications. And the payload is in index.js file.
This is my function:
func setActionCategories() {
let acceptAction = UNNotificationAction(
identifier:NAString().notificationAcceptIdentifier(),
title:NAString().accept().capitalized,
options: [.init(rawValue:0)])
let rejectAction = UNNotificationAction(
identifier:NAString().notificationRejectIdentifier(),
title:NAString().reject().capitalized,
options: [.init(rawValue:0)])
let actionCategory = UNNotificationCategory(
identifier:NAString().notificationActionCategory(),
actions: [acceptAction, rejectAction],
intentIdentifiers: [],
options: [.customDismissAction])
UNUserNotificationCenter.current().setNotificationCategories(
[actionCategory])
}
This is where I am performing action on buttons:
func userNotificationCenter(_ center: UNUserNotificationCenter,
didReceive response: UNNotificationResponse,
withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
let notificationType = userInfo[Constants.FIREBASE_NOTIFICATION_TYPE] as? String
if response.notification.request.content.categoryIdentifier == NAString().notificationActionCategory() {
switch response.actionIdentifier {
case NAString().notificationAcceptIdentifier():
Print(“Accept”)
case NAString().notificationRejectIdentifier():
Print(“Reject”)
}
}
completionHandler()
}