【问题标题】:Alert coming in iOS 10 when pushnotification in foreground even when no alert code is written即使没有编写警报代码,在前台推送通知时也会在 iOS 10 中发出警报
【发布时间】:2018-04-05 11:49:50
【问题描述】:

我的 iOS 应用程序遇到了一个奇怪的问题。当我的应用程序处于前台并收到推送时,它会显示在通知中心,并且同样会显示在警报中。

但我没有在 Appdelegate 中的任何推送通知接收委托方法中编写任何警报显示代码。

当应用程序处于前台时,如何避免这种不需​​要的警报视图。 ??

【问题讨论】:

    标签: ios objective-c apple-push-notifications


    【解决方案1】:

    这是由于实现了委托

    目标-C

    - (void)userNotificationCenter:(UNUserNotificationCenter *)center 
                       willPresentNotification:(UNNotification *)notification 
                         withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
    
                 completionHandler(UNNotificationPresentationOptionAlert); // SHOWS ALERT
    }
    

    斯威夫特 3

    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?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-19
      • 2017-10-30
      • 1970-01-01
      相关资源
      最近更新 更多