I am currently facing an issue where I need to be able to change the actions of a UNNotificationCategory based on information sent with the notification. Currently my categories are set up similarly to this:
func registerNotificationSettings(){
let acceptAction = UNNotificationAction(identifier: "accept", title: "accept", options: [])
let denyAction = UNNotificationAction(identifier: "deny", title: "deny", options: [])
let acceptCategory = UNNotificationCategory(identifier: "2", actions: [acceptAction], intentIdentifiers: [], options: [])
let denyCategory = UNNotificationCategory(identifier: "1", actions: [denyAction], intentIdentifiers: [], options: [])
let center = UNUserNotificationCenter.current()
center.setNotificationCategories([acceptCategory, denyCategory])
center.requestAuthorization(options: [.alert, .badge, .sound]){
(granted, error) in
if (granted){
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
}
}
}
This configuration is working, however, I need the ability to change the default action for each category based on user settings. For example, in the "denyAction" "deny" may need to be change to "reject", or in the "acceptAction" "accept" may need to be changed to "confirm". These are settings that we have made variable for the user to specify themselves within the application, and I have no way of knowing what they may change it to.
Currently we have the notifications sending "response" dictionaries in the userInfo of each notification, but I don't know how it is possible to change notification actions at the time of receiving the notification. The only documentation I have found sets these actions ahead of time. Does anyone know if this is possible?