Plivo iOS SDK V2 - Setting up Push Credentials

The following section explains on how to receive incoming calls on the Plivo iOS SDK v2 using pushkit. You no longer need KeepAlives to regularly keep the application awake for incoming calls.

To receiving an incoming call, you must:

  1. Enable VoIP services in your application.
  2. Create the VoIP service certificate.
  3. Create a provisioning profile for your app.
  4. Create a push credential (.p12 file) using the VoIP certificate.
  5. Update the information in the Plivo dashboard.

Push Notification is very energy efficient as it is delivered on a shared socket. You don’t need to allow push notification, it works without the user knowing about it.

Device token is unique to both the device and your application. At launch, the app communicates with the APNs and receives its device token. The server must include this device token in every notification it sends.

Let us see each of these steps in detail.

1. Enable VoIP services in your application

To enable VoIP services from XCode, select the “Capabilities” tab and enable the following settings:

  1. Make sure “Push Notifications”is set to On.
  2. Within “Background Modes”, enable “Audio, AirPlay, and Picture in Picture”, “Voice over IP”, and “Remote Notifications” settings.

You must also add a valid certificate for the push notifications to work. Below is a summary of the process for creating and adding certifications for enabling push notifications in the iOS app. For more information on Apple Push notification, click here.

2. Create VoIP Service Certificate

To create a VoIP service certificate, you must:

  1. Create a certificate signing request (CSR)
  2. Create the service certificate using the CSR

Create a Certificate Signing Request (CSR)

Certificate signing request (CSR) is a prerequisite for creating a certificate in the iOS Dev Center. To generate the CSR:

  1. Open Keychain access from Launchpad on your Mac. image alt text

  2. From the “Keychain Access” menu, navigate to Certificate Assistant > Request a Certificate From a Certificate Authority. image alt text

  3. Enter a your Email Address, a common name for the certificate, and the Email Address of the Certificate Authority, and then click Continue

  4. The certificate is saved on your disk. Click Done.

Create the service certificate using the CSR

  1. On the Apple Developer portal, navigate to the Certificates section (production tab) in Apple Developer portal (iOS certificates). (https://developer.apple.com/account/ios/certificate) image alt text

  2. Click Add Certificate to add a new Production certificate. image alt text

  3. In the certificate type, select VoIP Services Certificate, and then click Continue. image alt text
    • Select VoIP Services Certificate image alt text
  4. Click Continue. image alt text

  5. To select and upload the CSR file generated from Keychain, click Choose File. image alt text

  6. To download and save the VoIP certificate, click Download. image alt text
    • Navigate to the download location to find the .cer file.
      image alt text
  7. Double click on the cert file will add it to Mac’s Keychain ideally. You can also drag and drop the certificate to keychain manually .

3. Create a provisioning profile for your app

To create a provisioning profile for your app navigate to the Provisioning Profiles section on Apple Developer Portal.

For Sandbox

  1. Select Provisioning Profile type as Distribution.
    image alt text

  2. Click + to add a new Provisioning Profile.
    image alt text

  3. To set up Provisioning Profile For Sandbox Environment, select iOS App Development as the provisioning profile type.
    image alt text

  4. Click Continue.
  5. From the App ID list, select your App ID.
    image alt text

  6. Select the developer certificates to include in this provisioning profile.
    image alt text

  7. Select the developer devices to include in this provisioning profile.
    image alt text

  8. Enter a name for the provisioning profile.
    image alt text

  9. Click Download to download and save the generated profile.
    image alt text

For Production

  1. Select provisioning profile type as Distribution.
    image alt text

  2. Click + to add a new Provisioning Profile.
    image alt text

  3. To set up Provisioning Profile For Sandbox Environment, select iOS App Development as the provisioning profile type.
    image alt text

  4. Click Continue.
  5. Select your App ID.
    image alt text

  6. Select the developer certificates to include in this provisioning profile.
    image alt text

  7. Select the developer devices to include in this provisioning profile.
    image alt text

  8. Enter a name for the provisioning profile.
    image alt text

  9. Click Download to download and save the generated profile.
    image alt text

Note: The file is downloaded with .mobileprovision extension.

4. Create Push Credential with your VoIP Service Certificate

Once you have generated the VoIP Services Certificate, make sure to update it in your Plivo dashboard. This enables Plivo to send push notifications to your app on your behalf.

To create Push Credentials with your VoIP Service Certificate

  1. Export your VoIP Service Certificate as a .p12 file from Keychain Access.
    image alt text

  2. Enter a unique name for the certificate and then click Save.
    image alt text

Note: You need not enter a password to create the .p12 file. Click OK if you are prompted to enter a password to protect the exported item. The app private key will get stored in .p12 format.
image alt text

5. Update the information in Plivo dashboard

The certificate key and the private key need to be generated from the .p12 file. To generate the files:

1. Create a Certificate Key

Convert the p12 App private Key to a .pem format certificate.

Run the following command to create certificates and sign them with p12 App private key.

openssl pkcs12 -in Certificates.p12 -nokeys -out cert.pem -nodes

Next, create a private key from the .p12 file.

openssl pkcs12 -in Certificates.p12 -nocerts -out key.pem -nodes 

Run the following command to process the RSA key:

openssl rsa -in key.pem -out key.pem

The RSA Key and Certificate will be generated. image alt text

image alt text

2. Updating information in Plivo dashboard

  1. From the certificate file, strip anything outside of —–BEGIN CERTIFICATE—– and —–END CERTIFICATE—– boundaries.
  2. From the key file, strip anything outside of —–BEGIN RSA PRIVATE KEY—– and —–END RSA PRIVATE KEY—– boundaries.
  3. Paste this text into the UI available in the Plivo Dashboard. image alt text

Based on the types of profile and certificate generated from Apple Developer console, choose from either Production or Sandbox environment. Note: You can change the environment from sandbox to production, but not from production to sandbox. To change your environment to sandbox from production, delete the certificate and create a new one for sandbox. By deleting the production certificate, you will stop receiving incoming calls by all live apps.

  1. Click Save to update the changes. image alt text