VoxImplant. Blog

Push Notifications for iOS

VoxImplant push notifications for iOS are based on the Apple VoIP Push Notifications. Using notifications, a device can be awakened up and an app started before a call arrives. Our iOS SDK contains a sample application with all the code needed to handle push notification. Following tutorial explains that code and describes additional steps that should be performed to have a working Push Notifications solution for your mobile applications.

Push notifications are available since Android SDK version 1.1.0

Configure the iOS project

  • Open project in the XCode
  • Switch to the Project Navigator and click on the project
  • Click on the Capabilities pane
  • Enable Push Notifications and following Background Modes: “Audio, AirPlay, and Picture in Picture”, “Voice over IP”, “Background fetch” and “Remote notifications”

Handle push notifications

  • Subscribe to push notifications at the application start:
    1. PKPushRegistry *voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
    2. voipRegistry.delegate = self;
    3. voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
  • Handle incoming credentials refresh and pass token to the Voximplant SDK:
    1. - (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(PKPushType)type {
    2. // 'self.sdk' is an instance of the 'VoxImplantSDK'
    3. [self.sdk registerPushNotificationsToken:credentials.token];
    4. }
  • After push notification is received, if the application is not connected to Voximplant cloud, it should reconnect in order to handle an incoming call. It is strongly recommended to disable connectivity check when connecting after the push notification:
    1. - (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type {
    2. NSDictionary* custom = [[payload.dictionaryPayload objectForKey:@"aps"] objectForKey:@"voximplant"];
    3. if (custom) {
    4. // This call notifies Voximplant cloud that notification is successfully received.
    5. [self.sdk handlePushNotification:payload.dictionaryPayload];
    6. }
    7. }

Add certificates to the Voximplant cloud

  1. Login into the Apple developer website
  2. Click on the Certificates, Identifiers & Profiles
  3. Click on the Development or Production depending on your target
  4. Click on the “+” sign in the top-right corner
  5. Select the VoIP Services Certificate and click Continue
  6. Select the target application in the App ID and click Continue
  7. Follow on-screen instructions and download the voip_services.cer file
  8. Double-click the downloaded file and import it into the OSX Keychain of your development computer
  9. In the Keychain interface right-click imported certificate and export it as VoxDemo.p12 file with a password
  10. Login into the Voximplant control panel
  11. Select Settings, Mobile Push Certificates from the top menu.
  12. Click on the Add Certificate
  13. In the Certificate for list select the APPLE VOIP
  14. Click on the Choose File and upload the VoxDemo.p12 file
  15. Enter password you have used while generating a file from your Keychain interface
  16. Select Development or Production to the same selection you have previously selected while generating the certificate.
  17. Click on the Add button
  18. Click on the Certificates List, then on the Bind app button for the certificate just added
  19. In the Bind certificate to application window select the Voximplant application that will issue the calls and click on the Save button.

Modify VoxEngine scenario

In order for Voximplant cloud to send push notification to applications, the JavaScript scenario that initiates a call should include a push notification helper:

require(Modules.PushService)

Push notifications are sent automatically

Just use a callUser method from the VoxEngine scenario and push notification will be automatically sent to the app so the app can wake up, connect to Voximplant, login and accept the call.

Use tokens or keys for better security

Voximplant support 3 ways to login from the SDK: with a username and a password, with a username and a token or with a one-time login key. Saving the password is not secure, so we would recommend to use “token” or “ke”y approach. The token is received from an event after the successful login, can be saved and used later instead of a password. Please refer to the tutorial for details. The “login key” approach allows to completely exclude password usage on client-side by offloading it to your backend. Please refer to the tutorial for details.

Comments