44

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

rahulg
  • 2,183
  • 3
  • 33
  • 47
  • The quickest answer that I can direct you to, which will be the most robust answer in my opinion, is to look at the source code for Parse.com. Parse is owned by Facebook and I'm sure they are using some of the goodness of the whats app methods in their code. They just made themselve open source like last week: https://github.com/ParsePlatform/Parse-SDK-iOS-OSX . they have opened up everything that they do client side. They do idevice to idevice communication, push, background jobs on demand, and more, it's actually a very impressive chunk of code and it's all written in ObjC – Larry Pickles Aug 25 '15 at 06:56
  • 7
    This is just a hunch but it could be that the web version is disconnected from iOS after verifying with a secure token (QRCode). Whatsapp may allow you to continue using the web version until your session expires. – xoail Aug 25 '15 at 06:56
  • this is nothing to do with new iOS 8 AFAIK. Because same feature was available in wechat iOS version long time ago. (before iOS 8). So i guess @xoail comment is correct – Bluewings Aug 25 '15 at 07:28
  • sorry @xoail but you are wrong. Wechat might work like Skype or Facebook messenger. I am pretty sure that the whatsapp web version is connected to Background Service on iOS as, as soon as I put my phone in Airplane mode, the web client disconnects – rahulg Aug 25 '15 at 10:44
  • sorry @Bluewings but you are wrong. Wechat might work like Skype or Facebook messenger. I am pretty sure that the whatsapp web version is connected to Background Service on iOS as, as soon as I put my phone in Airplane mode, the web client disconnects – rahulg Aug 25 '15 at 10:44
  • @rahulg, I think the mobile app does nothing for the sync. It only takes role while login. Once the web login, it would gets data from the server, rather than the phone. The app is gone if you kill it in task manager. – Horst Aug 27 '15 at 10:59
  • Possible duplicate of https://stackoverflow.com/questions/32112433/how-whatsapp-web-works-on-ios/32269202#32269202 – fishinear Aug 28 '15 at 14:32
  • Yes, possible duplicate https://stackoverflow.com/questions/32112433/how-whatsapp-web-works-on-ios/32269202#32269202 – Iman Nia Sep 01 '15 at 20:56

3 Answers3

20

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.

Anders
  • 690
  • 6
  • 7
4

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.

xoail
  • 2,978
  • 5
  • 36
  • 70
  • Thanks but none seem to provide the final answer, especially the fact that I have disabled "Background Mode" still it works :-( – rahulg Aug 26 '15 at 06:33
  • @rahulg how long have you turned off background app refresh mode? It could be that there is a time limit that the Web version is authenticating with the App and the app is indeed making use of Background App Refresh. Like Website checks its DB to see if user session from App is still valid every 30 mins. – xoail Sep 03 '15 at 19:21
0

As mentioned in #32112433 by Steven Darbey this is most likely implemented using the new iOS 8 PushKit Service which includes a VoIP service notification type, allowing applications to resume from background. A misuse of the API for non-VoIP purposes, but Apple apparently putting a blind eye on it.

https://developer.apple.com/library/prerelease/ios/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html

nishanthshanmugham
  • 2,967
  • 1
  • 25
  • 29
user2525108
  • 239
  • 1
  • 3
  • 10