When a Stringee call is made, Stringee Server pushes a message to the client who receives the call. If the client has already connected to Stringee Server, the incoming call can be received via StringeeIncomingCallDelegate Protocol and you can ignore the pushed message. Otherwise (the client disconnects from Stringee Server or the app is killed) the client only receives a message pushed from Stringee Server. Then the client must connect to Stringee Server to receive the incoming call. This tutorial will walk you through the steps of integrating push notification into your app to receive Stringee push message.
The Callkit framework supports iOS 10 and above. Callkit lets Display the system-calling UI for your app's VoIP services, and coordinate your calling services with other apps and the system. For more information, see Callkit
The Pushkit framework supports iOS 8.0 and above. Pushkit sends specific types of notifications such as VoIP invitations, watchOS complication updates, and file provider change notifications... It's very useful for VoIP apps. For more information, see Pushkit
With Callkit and Pushkit support, you can display an incoming call:
Go to Stringee dashboard, choose Push Notification -> Choose your project -> Choose your existing app or create a new app.
Enter App name and Package name:
To integrate push notification, you must upload an APNs Auth Key. When sending push notifications using an APNs Auth Key, we require the following information about your app:
To create an APNs auth key, follow the steps below.
Visit the Apple Developer Member Center
Click on “Certificates, Identifiers & Profiles”. Go to Keys from the Left Menu. Create a new Auth Key by clicking on the “+” button.
On the following page, add a Key Name, and select APNs
Hit the Register button.
On this page, you will be able to download your auth key file. Please do not rename this file, and upload it as it is to our dashboard, as shown later below.
Locate and copy your Team ID – click on your name/company name at the top right corner, then select “View Account”.
Copy Team ID. Then go to the iOS app on Stringee dashboard and upload the APNs Auth Key. Click "Upload" button ==> Choose your APNs Auth Key, enter Key ID, Team Id ==> Upload.
Enable Push Notifications in Capabilities
Enable Voice over IP in Capabilities -> Background Modes
Register your app for VoIP push. Edit AppDelegate.h file
In AppDelegate.m file. Call the following method in the didFinishLaunchingWithOptions method.
func voipRegistration() {
let voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [.voIP]
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
voipRegistration()
return true
}
Implements the PKPushRegistryDelegate protocol
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
let token = pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined()
print("Voip token: \(token)")
self.stringeeClient.registerPush(forDeviceToken: token, isProduction: false, isVoip: true) { (status, code, message) in
print("registerPush: \(String(describing: message))")
}
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
let jsonData = JSON(payload.dictionaryPayload)
let payLoadData = jsonData["data"]["map"]["data"]["map"]
let callStatus = payLoadData["callStatus"].string
let callId = payLoadData["callId"].string
let pushType = jsonData["data"]["map"]["type"].string
let callSerial = jsonData["data"]["map"]["data"]["map"]["serial"].intValue
let alias = payLoadData["from"]["map"]["alias"].string
let number = payLoadData["from"]["map"]["number"].string
print("didReceiveIncomingPushWith: \(jsonData)")
}
To receive push notification, isProduction must be passed by a correct value:
You should register push notification when you connect Stringee server first time:
self.stringeeClient.registerPush(forDeviceToken: token, isProduction: false, isVoip: true) { (status, code, message) in
print("registerPush: \(String(describing: message))")
}
When you no longer want to receive push notification from Stringee server, you must call:
self.stringeeClient.unregisterPush(forDeviceToken: token, completionHandler: { status, code, message in
print("unregisterPush: \(String(describing: message))")
})
Now you complete integrating Stringee push message. You can view sample code on Samples.