iOS 应用程序在前台时忽略推送通知

Ignore push notifications when iOS app is in the foreground

我有一个相当大的 iOS 项目。当应用程序在前台收到通知时,通知会显示在看起来像 AlertView 的内容中。我想摆脱它。我不知道这是我很久以前自己编写的程序,还是项目中的某个框架(Parse、Onesignal、FBSDK)正在执行此操作。我的问题是,我如何才能找出警报视图的来源,以便删除该代码。我没有在任何地方实现 willPresentNotification 方法(我已经搜索了整个项目)。我确实有一个 didReceiveRemoteNotification 方法,尽管只有在点击通知时才应调用该方法,但我已尝试将其注释掉。我还在整个项目中搜索了 UIAlertView 和 UIAlertController,但无济于事。

OneSignal SDK automatically uses the new UserNotifications Framework,当在设备上检测到 iOS10。

在这种情况下,AppDelegate方法didReceiveRemoteNotification method not get called, instead methods in UNUserNotificationCenterDelegate被调用,被SDK捕获记录clicks/views。

OneSignal 使用 callback 处理收到的通知。

  • OSHandleNotificationReceivedBlock:当应用仅在焦点中收到通知时调用

  • OSHandleNotificationActionBlock:当用户打开或点击通知上的操作时调用。

  • OSNotificationOpenedResult:从用户收到的通知返回的信息。

您可以直接实施 UNUserNotificationCenterDelegate 方法来处理应用中的 notification-related 交互。