Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the web version of Whatsapp work on iOS devices considering the OS shuts apps in 30 seconds?

Now for those who don't know, can go to https://web.whatsapp.com/ and sync your Whatsapp chats by exchanging a QR code and chat via the web extension of the app.

I am not interested in how they have an initial handshake( might be communicating with whatsapp servers) nor how they sync data so fast for chatting (might be using Open sockets directly from device to client).

I am curious as to how the app works in Background on iOS . AFAIK running a background Intent Service is pretty simple. But not for iOS. iOS allows only up to 30 seconds after the app is shut down normally.

1) I tried crashing the App(swipe up) (Still the web version was running normally)

2) I disabled Background App refresh the web version didn't stop.

3) Even disable Notifications still the web version worked normally.

4) As well they do not have a Blue bar the likes when Google Maps is giving you directions that indicates the app is running in BG

5) Are they using Dummy Geo Fencing to keep them alive? (but that d require BG App Refresh too)

Is it some new feature on iOS 8 that was introduced and I am not aware of

like image 747
rahulg Avatar asked Aug 25 '15 06:08

rahulg


2 Answers

Just as a side note, Apple introduced the Notification Service extension point in iOS 10, which can be used to achieve this. The following applies only to iOS 9.x or earlier.


No app in iOS can be long alive in background with a keep-alive socket, or guaranteed to wake by remote notifications except those using VoIP background mode (OT: and IIRC Bluetooth background modes).

  • An app has only ~5 seconds of runtime on applicationDidEnterBackground: after being put in background, unless it is registered for any background modes or tasks. The app would be terminated if it runs out of time in this delegate method.
  • The background task model mentioned by @xoail has a app-specific, system-imposed time limit (up to 30 seconds...?) and cannot be extended. It is for an app to complete its current work, e.g. uploading a media, before being suspended. Background Transfer Service, since iOS 7.0, is an alternative for long running file transfer.
  • Silent Remote Notificaiton is observed to be triggered consistently only on charger and Wi-Fi, but always throttled by iOS otherwise. So it is sort of indeterministic - let alone the fact that this can be switched off by flipping the app's Background App Refresh switch.
  • VoIP background mode (in iOS 8 and later) guarantees to call the app's handler when a VoIP notification is received from APNs. But App Review Guidelines states clearly that background modes should only be used for their intended purpose.

So either Apple waives WhatsApp the use of VoIP background mode for purpose other than WhatsApp Call, or WhatsApp happens to get away from the "use your phone to sync" architecture and does something new for the iPhones.

like image 161
Anders Avatar answered Nov 17 '22 23:11

Anders


As per the docs the app can remain in the background performing finite updates to the App. You can continue extending the background process one after the other. Look into Perform finite-length tasks. I think killing the app from background still executes registered actions by the system.

Whatsapp does some clever web session token + background app token generation to keep session valid.

like image 24
xoail Avatar answered Nov 18 '22 00:11

xoail