【发布时间】:2018-04-05 11:49:50
【问题描述】:
我的 iOS 应用程序遇到了一个奇怪的问题。当我的应用程序处于前台并收到推送时,它会显示在通知中心,并且同样会显示在警报中。
但我没有在 Appdelegate 中的任何推送通知接收委托方法中编写任何警报显示代码。
当应用程序处于前台时,如何避免这种不需要的警报视图。 ??
【问题讨论】:
标签: ios objective-c apple-push-notifications
我的 iOS 应用程序遇到了一个奇怪的问题。当我的应用程序处于前台并收到推送时,它会显示在通知中心,并且同样会显示在警报中。
但我没有在 Appdelegate 中的任何推送通知接收委托方法中编写任何警报显示代码。
当应用程序处于前台时,如何避免这种不需要的警报视图。 ??
【问题讨论】:
标签: ios objective-c apple-push-notifications
这是由于实现了委托
- (void)userNotificationCenter:(UNUserNotificationCenter *)center
willPresentNotification:(UNNotification *)notification
withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
completionHandler(UNNotificationPresentationOptionAlert); // SHOWS ALERT
}
func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler(.alert)
}
在 iOS 10 中,您也可以在前台显示通知。 您可以通过仅在completionHandler 或注释completionHandler 中添加徽章来检查
参考:Displaying a stock iOS notification banner when your app is open and in the foreground?
【讨论】: