Push Notification code execution (forced-quit app)
Asked Answered
F

2

7

I was wondering how applications like Whatsapp were able to give a delivery receipt (double green check) to the sender of the message.

I have seen that even if you force-quit Whatsapp (using the app task switcher and swiping the app away), the sender still gets the delivery receipt (double green check) just at the moment the push notification is received on the phone. Clearly they are able to execute code (make a request to a backend, informing the delivery) when receiving the push notification.

Since iOS7 one can send a push notification payload with "content-available":1, this enables the receiver of the notification to execute user code, so, firstly I thought they were using this feature. However, if the user forced-quit the app then the user code is not executed when receiving the notification. Because of this I'm not able to mimic Whatsapp behavior.

I have enabled Capabilities>Background Modes and checked Remote notifications.

I'm handling the notification with this method:

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler

I'm sending the notification with this payload:

{
    "aps":{
            "alert":"Hello world",
            "sound":"MySound.wav",
            "content-available":1
    }
}

I have already checked:

I also read about PushKit (though I didn't try it), that maybe could help here, but my understanding is that the app would need to be a VOIP app. Clearly I don't want to require VOIP on my app to just execute code when receiving a push notification.

Thanks.

Franckot answered 14/8, 2015 at 18:33 Comment(0)
D
6

You just answered your question in your description.

  1. There is no way to wake the app through an regular push notification, if it was force-quit.

    See App Programming Guide for iOS:

    In most cases, the system does not relaunch apps after they are force quit by the user. One exception is location apps, which in iOS 8 and later are relaunched after being force quit by the user. In other cases, though, the user must launch the app explicitly or reboot the device before the app can be launched automatically into the background by the system.

  2. VoIP push notifications can wake the app, even if it was force-quit.

    See Voice Over IP (VoIP) Best Practices:

    Your app is automatically relaunched if it’s not running when a VoIP push is received.

  3. Two blue marks in WhatsApp mean, the recipient read the message. If you get two blue marks, just after the push notification was received, this is a design fault or bug in WhatsApp, since you can't tell, if the user actually read the notification. If you get two grey marks, that just means, the message was delivered to the device. Again, if you get two grey marks, just after the push notification was received and the app was force-quit, either WhatsApp is (mis)using VoIP push for this, or they just assume the push was delivered or will be delivered.

Danit answered 17/8, 2015 at 8:11 Comment(1)
Thanks Baris. I'm getting two green (grey) marks just afer the push notification was received no matter if the app was force-quit or not. I would guess then that they are using VoIP for this. I did some more research and tested sending a message to device that has installed Whatsapp on iOS7 which does not have VoIP pushes (PushKit is for iOS>=8), in this case, I didn't get the two green (grey) marks, so I can conclude that my theory (they are using PushKit VoIP pushes) is right.Franckot
H
0

This has actually been recently changed/fixed by iOS. I work on a push notification package with an example app, and demonstrate it: Push notification example app

Homorganic answered 28/7, 2023 at 1:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.