One App to rule them all
Since the news originally came out that iOS4 would allow multitasking, we’re asked everyday if and when we are going to add support for multitasking to our SIP clients, Acrobits Softphone and GroundWire. As usual with Apple and the iPhone, the answer is not straightforward and we need to examine iOS4 and multitasking in greater detail first.
To most people, multitasking means that several applications can run simultaneously, one in the foreground with the others in the background. Let’s be clear from the start that this is not how multitasking works on iOS4.
When you quit an application in iOS4, the operating system hibernates it. It is still in the device memory, but it is sleeping and cannot do anything. It can’t send keepalive packets to the SIP server, re-register for incoming calls or do all the other things a SIP Client must do.
There are ways to force the iOS4 not to hibernate the application. Unfortunately, this means keeping the app active all the time when it’s in the background and it will quickly drain your battery.
There is one option that looks promising at first glance; you can tell iOS4 that your application wants to be woken up if there is incoming network traffic. We thought that maybe if we use that, we can be woken up by an incoming call arriving over the network and give the user a chance to answer it. But again, there is a catch; you can only be woken up by incoming network traffic over a TCP connection. SIP and VoIP generally prefer the more lightweight UDP protocol and many (if not most) large SIP providers do not support TCP even as an option.
We don’t want to get to too technical here, but at this point it should already be obvious that the way iOS4 supports multitasking is not very useful for a SIP client. We’ll now focus on how GroundWire (and Softphone) deals with these limitations.
As mentioned above, we can force the application to stay alive and awake in the background. If you go to preferences and set “Keep iPhone awake” to “always”, GroundWire will detect situations when it’s being put to sleep in the background and prevent it. It will keep running in the background, keep the connection to the server and listen for incoming calls.
This works fine, the only drawback is that Groundwire running in the background all the time drains the battery pretty quickly. Give it a try, you will see.
Using TCP as the SIP transport protocol is necessary if we want to be woken up by incoming network traffic. You can find the transport protocol option in “Advanced” section of your “SIP Account Settings” - set it to TCP.
It’s possible (maybe even likely) that your SIP provider doesn’t support TCP; if you can’t register using TCP, they most likely don’t. Check with your provider and if this is the case, leave the transport protocol as UDP and read on.
Next, go to your “SIP Account Settings” and set “Incoming Calls” to “In Background”. If your provider doesn’t support TCP, you can go into “Backgrounding Options” and fill in an outbound proxy that will convert the SIP traffic from TCP to UDP. If you don’t know of such a proxy, tap “Try Acrobits” and our experimental outbound proxy will be enabled.
Then, in the “Advanced” settings, set “Expires” to a high value, we recommend 1700. Groundwire can’t refresh your registration more often than once every 600 seconds, which is why a higher value is necessary.
That should do it. If you close GroundWire, you should be able to receive incoming calls natively (as opposed to through push notifications).
Drawbacks? There are many. The setup is quite complicated, therefore reliability is questionable. Providers often don’t support TCP, requiring you to rely on a 3rd party outbound proxy. The application is woken up by all incoming network traffic, which is not just incoming calls. Every keepalive packet will wake the application up and generate a reply, depleting your battery. Granted, it won’t drain the battery as quickly as Option 1 above, but it will still have a significant effect on battery life.
On the positive side, it is more secure than using Push Notifications, as your account credentials do not have to be uploaded to our Push server. If you have a good provider that supports TCP, the reliability should be comparable to Push Notifications.
In our opinion, multitasking support the way it’s implemented in iOS4 is not particularly useful for SIP clients. GroundWire uses every feature iOS4 provides, but it’s still not enough. It seems clear that Push Notifications will offer the same functionality as multitasking, but reliability will typically be better and battery drain will be minimal. With iOS4, if the application receives a push notification while in the background, it will switch to foreground much faster than before, when it had to be started up. If your turn on Screen Pushed Calls in the Softphone preferences, you can even open the Softphone and see the contact before you accept the call. Therefore, user experience with Push Notifications is greatly improved in iOS4.
Push Notifications are actually a pretty good solution to responding to events like incoming calls while preserving battery life. It is still the solution we recommend for incoming calls, even for iOS4.
Important Note: When switching from background to foreground, we re-register the account to make sure all is working correctly. This is expected behavior, it doesn’t mean the app was not listening for incoming calls when in the background.
Note for Asterisk Users: To enable TCP for Acrobits Softphone while leaving UDP as the primary protocol for other SIP clients, please add the following to sip config (you must have Asterisk 1.6):
Thanks to our users for this valuable information