如何在 userNotificationCenter 中检查哪个标识符用于触发本地通知?
How can I check in the userNotificationCenter which identifier was used to trigger local notification?
我想为不同的本地通知做不同的事情,这就是为什么我想知道如何检测使用哪个标识符发送本地通知。
我想在“willPresent notification”函数中执行操作,而不是在“didReceive Response”函数中执行操作。感谢您的帮助!
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound])
}
您可以使用
在 userNotificationCenter(_: willPresent: withCompletionHandler)
中获取 notification's
identifier
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let identifier = notification.request.identifier //here...
completionHandler([.alert, .sound])
}
我想为不同的本地通知做不同的事情,这就是为什么我想知道如何检测使用哪个标识符发送本地通知。
我想在“willPresent notification”函数中执行操作,而不是在“didReceive Response”函数中执行操作。感谢您的帮助!
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound])
}
您可以使用
在userNotificationCenter(_: willPresent: withCompletionHandler)
中获取 notification's
identifier
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let identifier = notification.request.identifier //here...
completionHandler([.alert, .sound])
}