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 in the top right corner.
On the following page, add a Key Name, and select APNs
Hit the Continue 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.
Add Pushkit framework to your app:
Enable Push Notifications in Capabilities
Enable Voice over IP in Capabilities -> Background Modes
In Xcode 9, you must add a Info.plist file
<key>UIBackgroundModes</key>
<array>
<string>voip</string>
</array>
Register your app for VoIP push. Edit AppDelegate.h file
In AppDelegate.m file. Call the following method in the didFinishLaunchingWithOptions method.
- (void) voipRegistration {
dispatch_queue_t mainQueue = dispatch_get_main_queue();
// Create a push registry object
PKPushRegistry * voipRegistry = [[PKPushRegistry alloc] initWithQueue: mainQueue];
// Set the registry's delegate to self
voipRegistry.delegate = self;
// Set the push type to VoIP
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self voipRegistration];
return YES;
}
Implements the StringeeConnectionDelegate protocol
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials: (PKPushCredentials *)credentials forType:(NSString *)type {
}
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
NSLog(@"didReceiveIncomingPushWithPayload %@", payload.dictionaryPayload);
}
Register push notification to Stringee server.
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials: (PKPushCredentials *)credentials forType:(NSString *)type {
// Register VoIP push token (a property of PKPushCredentials) with server
NSString *token = [[credentials.token description] stringByTrimmingCharactersInSet: [NSCharacterSet characterSetWithCharactersInString:@"<>"]];
token = [token stringByReplacingOccurrencesOfString:@" " withString:@""];
[stringeeClient registerPushForDeviceToken:token isProduction:NO isVoip:YES completionHandler:^(BOOL status, int code, NSString *message) {
NSLog(@"%@", message);
}];
}
To receive push notification, isProduction must be passed by a correct value:
You should register push notification when you connect Stringee server first time:
[stringeeClient registerPushForDeviceToken:token isProduction:NO isVoip:YES completionHandler:^(BOOL status, int code, NSString *message) {
NSLog(@"%@", message);
}];
When you no longer want to receive push notification from Stringee server, you must call:
[stringeeClient unregisterPushForDeviceToken:token completionHandler:^(BOOL status, int code, NSString *message) {
NSLog(@"%@", message);
}];
Now you complete integrating Stringee push message. You can view sample code on Samples.