© 2019 NewAge SMB
Steps to Implement VOIP Notification

Steps to Implement VOIP Notification
20 March, 2018

 
Step 1
Create a new VoIP Services Certificate for your VoIP app in your developer account, download the certificate and import it into the Keychain Access app and create your pem file.

Step 2
Like all apps that support background operation, your VoIP app must have background mode enabled in the Xcode Project > Capabilities pane.Select the checkbox for Voice over IP or update plist (iOS 11 or later) with the following:
  • UIBackgroundModes
  • voip
Step 3
Enable Push notification in capabilities.

Step 4
To configure your app to receive VoIP push notifications, link to the PushKit framework in your app delegate (or some other location in your app). Then, create a PKPushRegistry object, set its delegate to self, and register to receive VoIP pushes. Open AppDelegate.swift and at the top add the import PushKit statement.Then, in the didFinishLaunchingWithOptions part of the application function make sure you register for notifications like this:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let notificationSettings = UIUserNotificationSettings(types: [.badge, .sound,.alert], categories: nil)
//register the notification settings
application.registerUserNotificationSettings(notificationSettings)
//output what state the app is in. This will be used to see when the app is started in the background
NSLog("app launched with state \(application.applicationState)")
return true
}


Since we are using the registerUserNotificationSettings method we need to implement it’s delegate callback application(application: UIApplication, didRegisterUserNotificationSettings

notificationSettings:UIUserNotificationSettings):

func application(_ application: UIApplication, didRegister notificationSettings: UIUserNotificationSettings) {
//register for voip notifications
let voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
voipRegistry.desiredPushTypes = Set([PKPushType.voIP])
voipRegistry.delegate = self
}


– Add the required PKPushRegistryDelegate:

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {

//print out the VoIP token. We will use this to test the notification. let deviceToken:
String = pushCredentials.token.reduce(“”, {$0 + String(format: “%02X”, $1) })
NSLog(“voip token: \(deviceToken)”)
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType){
let payloadDict = payload.dictionaryPayload[“aps”] as? Dictionary<String, String>
NSLog(“incoming voip notfication: \(payload.dictionaryPayload)”)
}
 

Now the app can receive Push notification.

Note: Unlike user notifications, which are supported by the UserNotifications framework, PushKit notifications are never presented to the user — they don’t present badges, alerts, or sounds.It doesn’t need user’s permission to enable notification, also the app would not be accepted in the app store if it doesn’t additionally provide Voip functionality to the user and is just using Voip push instead of regular pushes.
Reference: – https://developer.apple.com/library/content/documentation/Performance/Conceptual/EnergyGuide-iOS/OptimizeVoIP.html
– http://www.nikola-breznjak.com/blog/ios/create-native-ios-app-can-receive-voip-push-notifications/
 

Our pricing starts from as low as $5K
Why wait when now is the right time to build your app and chase your dream?

Get Started Now