iOS Push Notification When app is killed

泪湿孤枕 提交于 2019-12-09 23:55:50

问题


I was wondering how does WhatsApp handle the Video Push Notification when the app is killed from the background. Taking into consideration that the app icon is clicked and not the notification.

1- The Push Notification keeps showing every 5 seconds

2- The Ringtone plays single time although the app keeps showing push notifications for around 30 seconds.


回答1:


When app is in killed state, didReceiveRemoteNotification method will not be called. Then on the tap of notification application(_:didFinishLaunchingWithOptions) method will be called. launchOption contains the payload if app is launched by tap on notification. For that write the given code in this method:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
       if launchOptions != nil{
         let userInfo = launchOptions? 
         [UIApplicationLaunchOptionsKey.remoteNotification]
          if userInfo != nil {
        // Perform action here
         }
    }

All your payload data will be available in launchOptions?[UIApplicationLaunchOptionsKey.remoteNotification] & perform your app logic(navigation..) from there.

Refer this link for effective push notifications handling




回答2:


You can do it using iOS VoIP Push Notifications. VoIP push enables apps to become active even in the background and forcefully killed by user. All voice and video calling application use this priority push service.

Here is great Apple guide about Voice Over IP (VoIP) Best Practices. One of the main use case – use VoIP Push Notifications to Avoid Persistent Connections.

In order to use VoIP pushes you have to connect iOS PushKit framework. You can config your own server or other third party provider.



来源:https://stackoverflow.com/questions/51302525/ios-push-notification-when-app-is-killed

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