3

I am building an iOS App ( Using Swift) where I want like to process Notification even though my app has been closed (force closed).

  • I am receiving a Notification alert, however it is not processed till user click on notification badge.

  • However, when I check notification behavior or WhatsApp is seema notification get process even though Whatsapp is closed before use tap on notification badge.

  • I have search across forums and all most ever where it has been mention that your notification can not process if App is not running. ( It can process if App is in Background or Foreground )

My Question : If as per Apple documentation if App can not process the notification if it is not running then how Whatsapp has managed to do so.

How can I achieve same behavior at my app ?? I will highly appreciate for right technical solution and I believe there are hundreds of developers might have same query.

Dhaval Patel
  • 608
  • 7
  • 15
  • you may use `content-available` in notification payload but it has limitation too. – Mahendra Feb 06 '19 at 12:34
  • Not sure but what's app is VOIP based app so it can start it's process even in killed state on some VOIP signals. Just like what's app can share live location continuously – Prashant Tukadiya Feb 06 '19 at 12:44
  • Please check the following thread: https://forums.xamarin.com/discussion/67698/ios-notifications-while-app-is-closed – DJ-Glock Feb 06 '19 at 12:46
  • I think this question could be helpful, but it's for obj-c https://stackoverflow.com/questions/38512456/handling-push-notifications-when-app-is-not-running-i-e-totally-killed – DJ-Glock Feb 06 '19 at 12:50
  • I guess it depends if you are sending text notification or data notification. –  Feb 06 '19 at 14:30

2 Answers2

6

As WhatsApp is a VoIP application, it is entitled to use PushKit:

PushKit notifications differ from the ones you handle using the UserNotifications framework. Specifically, PushKit notifications never display alerts, badge your app's icon, or play sounds. They also have the following advantages over user notifications:

  • The device wakes only when it receives a PushKit notification, which can improve battery life.
  • Upon receiving a PushKit notification, the system automatically launches your app if it isn't running. By contrast, user notifications aren't guaranteed to launch your app.
  • The system gives your app execution time (potentially in the background) to process PushKit notifications.
  • PushKit notifications can include more data than user notifications.

Note the second bullet point.

If your app meets the criteria for PushKit use (VoIP app, Watch Complication update or file provider update) then you can use it.

Update

In iOS 13 and later an app must report an incoming CallKit call in response to a VoIP push or it will be terminated. This means that in general VoIP or PushKit pushes cannot be used for messaging or other purposes, but WhatsApp doesn't do this. How?

They have a restricted entitlement com.apple.developer.pushkit.unrestricted-voip.

This entitlement is not granted any more and was intended to give apps with millions of users more time to adopt the new approach.

Paulw11
  • 108,386
  • 14
  • 159
  • 186
  • Used to be true. Now you need to call CallKit if using PushKit for VoIP (> iOS 13), which Whatsapp doesn't do all the time (e.g., video call notifications). So the OP question remains the same... – tomasyany Dec 31 '20 at 15:16
  • 1
    WhatsApp has a special entitlement that allows unlimited voip push – Paulw11 Dec 31 '20 at 20:16
-1

They use silent notification. Silent notifications waken up the app for 30 seconds in the background and then you can do whatever you need.

For complete details, you can check this link. https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_updates_to_your_app_silently

Hitesh Agarwal
  • 1,943
  • 17
  • 21