How to change how a remote notification is presented before presentation?

馋奶兔 提交于 2019-12-01 14:00:01

问题


How should I change how a remote notification is presented in iOS before the system presents it? In fact, silence it. There are times where my app has canceled a Firebase topic subscription locally, but that cancellation is not delivered to the server in time. So, when our app is not running(in the background OR NOT RUNNING AT ALL), the server would still send a message to that Firebase topic and iOS will receive it.

My question is, how can I intercept a notification, and check whether it should be presented and silent it if needed? I need to support iOS 9 as well so UNNotificationServiceExtension does not suit my needs.

Thanks.


回答1:


There is no interception possible for remote notifications.

But the thing you want to do is possible like:

  • You modify the notification payload to be a silent push notification
  • You opt-in the Remote Notifications in background modes of your app's capabilities
  • Then use local notifications. When you receive a remote notification from your server, you will be able to decide to show or not any local notifications.

Footnote: In this approach, if the user has killed the app by swiping it up in the fast app switching mode, you won't be able to get any callbacks for your app in background when you receive a remote notification.




回答2:


That's a great question and currently there is no solution for this problem o iOS.

You can read about this on the Apple guide for local and push notifications.

https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/

PS: If by silent you meant change the sound that the notification makes, you can do it. https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ModifyingNotifications.html#//apple_ref/doc/uid/TP40008194-CH16-SW1



来源:https://stackoverflow.com/questions/49621956/how-to-change-how-a-remote-notification-is-presented-before-presentation

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