Uda*_*iya 1 apple-push-notifications ios swift
当我没有收到通知时,我不想提出userId通知userInfo.
那么如何才能停止通知呢?
我试过的代码:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
print("willPresent notification")
let aps = notification.request.content.userInfo[AnyHashable("aps")]!
guard let data = aps as? [String: Any] else{ return}
if let userId = data["userId"] as? String {
completionHandler([.alert, .badge, .sound])
}else{
return
}
}
Run Code Online (Sandbox Code Playgroud)
但仍然会显示通知.
试试这样吧
if let userId = data["userId"] as? String {
completionHandler([.alert, .badge, .sound])
} else {
completionHandler([])
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
74 次 |
| 最近记录: |