Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS Push Notification When app is killed

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.

like image 539
Ali Avatar asked Jul 12 '18 09:07

Ali


1 Answers

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

like image 162
Prasath R Avatar answered Oct 24 '22 21:10

Prasath R