我想为不同的本地通知做不同的事情,这就是为什么我想知道如何检测用于发送本地通知的标识符。
我想在">将呈现通知"功能中执行操作,而不是在"didReceive响应"功能中执行操作。感谢您的帮助!
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])
}