Ignore push notifications when iOS app is in the foreground

浪尽此生 提交于 2020-01-05 15:15:14

问题


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.


回答1:


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

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 use callback to handle received Notification.

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

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

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

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



来源:https://stackoverflow.com/questions/49219998/ignore-push-notifications-when-ios-app-is-in-the-foreground

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!