SIGN UP

Push Notifications

Voximplant push notifications for iOS are based on the Apple VoIP Push Notifications for calls and Apple Push Notifications for messaging. Using notifications, a device can be awakened up and an application can be started before a call or a message arrives. You can check our sample application with all the code needed to handle push notifications. 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 iOS SDK version 1.1.0

Configure the iOS project

  • Open project in the XCode
  • Switch to the Project Navigator and click on the project
  • Go to the Capabilities tab at the top panel
  • Enable Push Notifications and following Background Modes: "Audio, AirPlay, and Picture in Picture", "Voice over IP" (if you need to handle calls), "Background fetch" and "Remote notifications"

Handle push notifications

  • Subscribe to push notifications at the application start:
    PKPushRegistry *voipRegistry = [[PKPushRegistry alloc]
        initWithQueue:dispatch_get_main_queue()];
    voipRegistry.delegate = self;
    voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
    
  • Handle push credentials update and pass a new token to the SDK:
    - (void)pushRegistry:(PKPushRegistry *)registry 
      didUpdatePushCredentials:(PKPushCredentials *)credentials 
                       forType:(PKPushType)type {
        // 'self.client' is an instance of the 'VIClient'
        [self.client registerPushNotificationsToken:credentials.token];
    }
    
  • After a push notification is received, you have to pass dictionaryPayload to the SDK via the [VIClient handlePushNotification:] API. If the application is not connected to the 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.
    - (void) pushRegistry:(PKPushRegistry *)registry 
      didReceiveIncomingPushWithPayload:(PKPushPayload *)payload 
                                forType:(PKPushType)type {
        NSDictionary* custom =
            [payload.dictionaryPayload objectForKey:@"voximplant"];
        if (custom) {
            // This call notifies the Voximplant cloud 
            // that notification is successfully received.
            [self.client
                handlePushNotification:payload.dictionaryPayload];
        }
    }
    

Generate an Apple certificate

  1. Log in into the Apple developer website
  2. Click on the Certificates, ID's & Profiles
  3. Click on the "+" sign at the top-right corner
  4. Select the VoIP Services Certificate if you're going to handle calls notifications; despite this type of certificate is located in the Production section, it suits for both production and debug/sandbox builds.
    In case of messaging notifications, select Apple Push Notification service SSL either in Development or Production section. Click Continue
  5. Select the target application in the App ID and click Continue
  6. Follow on-screen instructions and download the voip_services.cer file
  7. Double-click the downloaded file and import it into the OSX Keychain of your Mac
  8. In the Keychain interface right-click imported certificate and export it as .p12 file with a password

Add certificates to the Voximplant cloud

  1. Log in into the Voximplant control panel
  2. Select Settings, Mobile Push Certificates from the top menu.
  3. Click on the Add Certificate
  4. In the Certificate for list select APPLE VOIP for calls or APPLE for messaging
  5. Click on the Choose File and upload the .p12 file
  6. Enter password you have used while generating a file from your Keychain interface
  7. Choose Production or Development version depending on your target. The Production version works only with release builds for TestFlight and AppStore. The Development version works with debug/sandbox builds (which are built from Xcode locally).
  8. Click on the Add button
  9. Click on the Certificates List, then on the Bind app button for the certificate just added
  10. In the Bind certificate to application window select the Voximplant application that will issue the calls/messages and click on the Save button.

Modify VoxEngine scenario

In order to allow the 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 the callUser method from the VoxEngine scenario and push notifications will be automatically sent to the app, so the application can wake up, connect to the Voximplant cloud, log in and accept the call.

Use tokens or keys for better security

Voximplant support 3 ways to log in from the SDK: with a password, a token or a one-time login key. Saving the password is not secure, so we would recommend to use the "token" or "key" approach.

The token is received from an event after the successful login, can be saved and used later instead of password. Please refer to the tutorial for details.

The "login key" approach allows to completely exclude password usage on the client side by offloading it to your backend. Please refer to the tutorial for details.