iOS 10, released this week, makes it even easier to integrate great VoIP experiences with your iOS applications. Today we’re proud to launch the Public Beta of the new Programmable Voice SDK for iOS. This SDK is designed as the next version of the currently available Twilio Client SDK v1.2.11 for iOS. You’ll notice a few changes such as out-of-the-box support for Apple’s VoIP Services Push Notifications (powered by Twilio’s Notify infrastructure).
Reaching your users
Any mobile app that allows a user to receive an incoming call has to make sure it can reliably deliver a call notification to the user in question. A good solution to this problem will reach the user every time, no matter whether the application is in the foreground, background, or not running at all. It will also handle any changes in the device’s network connectivity. A good solution will make sure the user knows they’re receiving a call, no matter whether the device has switched between Wifi and 4G, or changed push notification permissions.
Taking it a step further, a really good solution would ensure that all of the above happens quickly. When you use a VoIP app to call one of your friends, you shouldn’t have to sit around waiting for your friend to answer for an unusually long time. And your friend should receive a notification within milliseconds of you placing the call.
A great solution to this problem will deal with users that have many devices–and will notify the user that they’re receiving an incoming call on all the devices where they have your app installed.
The challenge of VoIP notifications
Building this ideal solution hasn’t always been easy. Earlier versions of iOS required that developers use the platform’s VoIP Socket API. This API enabled your app to ask the operating system to monitor a socket even when your app was in the background. If iOS received any data on this socket–like the notification for an incoming call–it would wake up your app and give you a few moments to execute some code, so you could do things like display a notification to the user and negotiate the actual call if they decided to accept the call.
But this approach had some downsides. The biggest problem was resource consumption. Keeping a persistent socket connection running in the background is expensive and can run down the battery. Apple did a lot to optimize performance over the years, but there was always some energy cost with this approach.
Further complicating issues was that fact that your back-end infrastructure had to be aware of the device’s socket (IP address and port) so it knew how to reach the user. Keeping this information up to date as users and their devices wander around the globe isn’t easy. iOS would intermittently wake up your app, giving you a few moments to send a message to update the device’s registration with your back-end. If that registration information was ever out-of-date, the only option was to fallback to APNS Push Notifications, which still might not reach the user (if they disabled push notifications for your app, for example), or might take too long to arrive to be a good fit for a real-time communications use case.
Apple made a giant step toward solving these problems when they introduced PushKit’s VoIP Push Notifications. VoIP Push Notifications have a bunch of advantages over the old approach. From Apple’s docs:
- The device is woken only when VoIP pushes occur, saving energy.
- Unlike standard push notifications, which the user must respond to before your app can perform an action, VoIP pushes go straight to your app for processing.
- VoIP pushes are considered high-priority notifications and are delivered without delay.
- VoIP pushes can include more data than what is provided with standard push notifications.
- Your app is automatically relaunched if it’s not running when a VoIP push is received.
- Your app is given runtime to process a push, even if your app is operating in the background.
A better way to call your user
With today’s Programmable Voice iOS SDK release, support for VoIP Push is now included “out of the box.” Your Programmable Voice iOS app now simply registers to receive incoming calls by providing a valid PKPushCredentials token, and Twilio manages all the rest.
When your TwiML application <Dial>s an identity that has registered for push notifications, Twilio automatically sends a VoIP push to the user’s device. If the user is simultaneously registered to receiving incoming calls in both a web application and an iOS app, Twilio will send a websocket-based notification to the web app and use VoIP Push to reach the iOS app.
VoIP Push registrations ensure that your user receives an incoming call notification as long as she has a network connection and Push notifications enabled in your app, no matter when her app registered to receive incoming calls, and no matter what networks she’s roaming between.
And if she has your app installed on multiple iOS devices (and thus multiple PKPushCredential tokens), Twilio will automatically send push notifications to all her registered devices–ensuring she reliably gets notified no matter which device she’s currently using, a capability made possible by our Notify platform that powers this experience.
More improvements, including CallKit support, on the way
The addition of Push Notification support is just the start. We’re adding features that will make it easy to use the Programmable Voice SDK with iOS 10’s new CallKit APIs.
We’ll also be bringing Push support to our Programmable Voice Android SDKs using Google Cloud Messenger and Firebase Cloud Messenger. Keep an eye on our blog for further updates.