当 iOS 应用程序在前台时忽略推送通知 [英] Ignore push notifications when iOS app is in the foreground

查看:49
本文介绍了当 iOS 应用程序在前台时忽略推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a fairly large iOS project. When the app receives a notifications while in the foreground, the notification is displayed in something that looks like an AlertView. I want to get rid of it. I have no idea if this is something I programmed myself a long time ago, or if one of the frameworks in the project (Parse, Onesignal, FBSDK) is doing this. My question is, how can I find out where that alert view is coming from, so I can remove that code. I have not implemented the willPresentNotification method anywhere (I have searched through the entire project). I do have a didReceiveRemoteNotification method, and even though that should only be called when a notification is tapped, I have tried commenting it out. I have also searched through the entire project for UIAlertView and UIAlertController, to no avail.

推荐答案

OneSignal SDK 在设备上检测到 iOS10 时自动使用新的 UserNotifications Framework.

OneSignal SDK automatically uses the new UserNotifications Framework, when iOS10 is detected on device.

在这种情况下,AppDelegate 方法 didReceiveRemoteNotification 方法没有被调用,而是 UNUserNotificationCenterDelegate 中的方法被调用,其中由 SDK 捕获以记录点击/查看.

In this case, the AppDelegate method didReceiveRemoteNotification method not get called, instead methods in UNUserNotificationCenterDelegate get invoked, which is captured by SDK to record clicks/views.

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

OneSignal use callback to handle received Notification.

  • OSHandleNotificationReceivedBlock:当应用程序在仅获得焦点时收到通知时调用

  • OSHandleNotificationReceivedBlock: Called when the app receives a notification while in focus only

OSHandleNotificationActionBlock:在用户打开或点击通知上的操作时调用.

OSHandleNotificationActionBlock: Called when the user opens or taps an action on a notification.

OSNotificationOpenedResult:用户收到的通知返回的信息.

OSNotificationOpenedResult: The information returned from a notification the user received.

您可以直接实现UNUserNotificationCenterDelegate 方法来处理通知相关的应用中的交互.

You can directly implement UNUserNotificationCenterDelegate methods to handling notification-related interactions in your app.

这篇关于当 iOS 应用程序在前台时忽略推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆