【发布时间】:2020-01-14 15:31:37
【问题描述】:
我的要求是防止显示远程通知。
如果应用程序处于前台或后台,我可以通过以下方法处理此问题:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
//logic hide notification here
}
public func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
//logic hide notification here
}
当应用程序被杀死时,我正在尝试处理 UNNotificationServiceExtension 中的逻辑,但它不起作用:
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
// logic hide notification here
}
我读过这篇文章:Is it possible to prevent a remote notification from being displayed? 上面说苹果不允许这样做,对吗?
【问题讨论】:
标签: ios xcode apple-push-notifications unnotificationserviceextension