iOS Push Notification When app is killed
Asked Answered
F

2

7

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.

Fairbanks answered 12/7, 2018 at 9:54 Comment(0)
K
7

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

Kaseykasha answered 12/7, 2018 at 10:12 Comment(4)
This is true if the user clicks on the notification, but if he clicks on the app icon. This case doesn't work.Fairbanks
OfCourse Yes. When owner is unaware of notifications received, will click on App icon -> App will open as per standard logic's not based on notification received. Owner have to go to necessary page to view updates.Kaseykasha
How to execute some code after receiving the push notification. Like replying back to the server with some data after receiving the push notification on the killed ios app via FCM or APNS?Amethyst
@Amethyst I am also curious to perform the same task. have you any luck so far?Adnah
E
3

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.

Empennage answered 12/7, 2018 at 10:24 Comment(5)
How to execute some code after receiving the push notification. Like replying back to the server with some data after receiving the push notification on the killed ios app via FCM or APNS?Amethyst
@Amethyst I think it seems impossible to interact with the app using notification when the app is in a killed state...Adnah
@Shamim Hossain do you think VoIP pushes can be used to other normal operations instead of audio and video calls ?Adnah
@shaqirsaiyed no, it should not be possible. Your app will be rejected if you do.Empennage
@ShamimHossain ok thanks, do you think there could be any way to interact notification to the application when the app is in the killed state? is it even feasible?Adnah

© 2022 - 2024 — McMap. All rights reserved.