La solicitud de notificación del usuario siempre viene con un identificador de acción predeterminado
Estoy usando UNUserNotificationCenterDelegate (> ios 10) y uno de los métodos de delegado donde puedo verificar la respuesta de la notificación siempre tiene actionIdentifier igual "com.apple.UNNotificationDefaultActionIdentifier" sin importar lo que haga. El "response.notification.request.content.categoryIdentifier" viene bien, con el valor esperado, pero request.actionIdentifier nunca viene correctamente ("mycustomactionidentifier" en el ejemplo a continuación). ¿Alguien sabe si me falta algo?
extension NotificationManager: UNUserNotificationCenterDelegate {
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Swift.Void) {
completionHandler([.alert,.sound])
}
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Swift.Void) {
if response.notification.request.content.categoryIdentifier == "TEST" {
if response.actionIdentifier == "mycustomactionidentifier" {
NSLog("it finally works dude!")
}
}
completionHandler()
}
}
Agregué la acción y la categoría al Centro de notificaciones:
let uploadAction = UNNotificationAction(identifier: "mycustomactionidentifier", title: "Uploaded", options: [])
let category = UNNotificationCategory(identifier: "TEST", actions: [uploadAction], intentIdentifiers: [])
center.setNotificationCategories([category])
y estoy enviando la solicitud poniendo el identificador correcto:
let uploadContent = UNMutableNotificationContent()
uploadContent.title = String(number) + " asset(s) added"
uploadContent.body = "Check your inventory to manage your assets!"
uploadContent.categoryIdentifier = "TEST"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 6, repeats: false)
let uploadRequestIdentifier = "mycustomactionidentifier"
let uploadRequest = UNNotificationRequest(identifier: uploadRequestIdentifier, content: uploadContent, trigger: trigger)
UNUserNotificationCenter.current().add(uploadRequest, withCompletionHandler: nil)