VOIP Sinch in iOS 11 not work in background - ios

I use Sinch VOIP to make calling between App-To-App in iOS 11.1.2
Work well when the application status is foreground but in background and terminated nothing happened after I open the application console print
Pubnub request SCHEDULED (ID=081E49C2-C30A-4B4B-840C-E6A6051E6F44, URL=https://rebtelsdk.pubnub.com/subscribe/sub-c-c5e52f20-d446-11e3-b488-02ee2ddab7fe/5e1e1309-136a-40d4-935f-2627ebe4e8f2B/0/0, NST-VoIP: NO)
Pubnub request STARTED (ID=081E49C2-C30A-4B4B-840C-E6A6051E6F44)
Pubnub request SUCCESS (ID=081E49C2-C30A-4B4B-840C-E6A6051E6F44):
(
(
),
15117251992031337
)
onPubSubSubscriptionSuccess: userInfo: {
channel = "5e1e1309-136a-40d4-935f-2627ebe4e8f2B";
subscribeSequence = 1;
timetoken = 0;
useVoIPNetworkServiceType = 0;
}
I upload VOIP & APNS certificates to Sinch dashboard and I used SINManagedPush & PushKit My code is
Setup Push Manager & SINClient in didFinishLaunchingWithOptions
self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
self.push.delegate = self;
[self.push setDesiredPushTypeAutomatically];
void (^onUserDidLogin)(NSString *) = ^(NSString *userId) {
[self.push registerUserNotificationSettings];
[self initSinchClientWithUserId:userId];
};
[[NSNotificationCenter defaultCenter]
addObserverForName:#"UserDidLoginNotification"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
NSString *userId = note.userInfo[#"userId"];
[[NSUserDefaults standardUserDefaults] setObject:userId forKey:#"userId"];
[[NSUserDefaults standardUserDefaults] synchronize];
onUserDidLogin(userId);
}];
- (void)initSinchClientWithUserId:(NSString *)userId {
if (!_client) {
_client = [Sinch clientWithApplicationKey:#"APP-Key"
applicationSecret:#"APP-Secret"
environmentHost:#"sandbox.sinch.com"
userId:userId];
_client.delegate = self;
_client.callClient.delegate = self;
[_client setSupportCalling:YES];
[_client enableManagedPushNotifications];
[_client start];
[_client startListeningOnActiveConnection];
_callKitProvider = [[SINCallKitProvider alloc] initWithClient:_client];
}
}
Get Device Token
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
[self.push application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler{
NSLog(#"User Info : %#",notification.request.content.userInfo);
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
[self.push application:[UIApplication sharedApplication] didReceiveRemoteNotification:notification.request.content.userInfo];
}
-(void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void(^)())completionHandler{
NSLog(#"User Info : %#",response.notification.request.content.userInfo);
completionHandler();
[self.push application:[UIApplication sharedApplication] didReceiveRemoteNotification:response.notification.request.content.userInfo];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo {
[self.push application:application didReceiveRemoteNotification:userInfo];
}
PushKit
-(void)voipRegistration
{
PKPushRegistry* voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
voipRegistry.delegate = self;
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
}
-(void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
{
[_client registerPushNotificationData:credentials.token];
}
-(void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type{
NSLog(#"invalidated");
}
4.Call voipRegistration when SINClient start
- (void)clientDidStart:(id<SINClient>)client {
NSLog(#"Sinch client started successfully (version: %#)", [Sinch version]);
[self voipRegistration];
}
5.Implement SINManagedPushDelegate & SINCallClientDelegate
- (void)client:(id<SINCallClient>)client didReceiveIncomingCall:(id<SINCall>)call {
UIViewController *top = self.window.rootViewController;
while (top.presentedViewController) {
top = top.presentedViewController;
}
[top performSegueWithIdentifier:#"callView" sender:call];
}
- (SINLocalNotification *)client:(id<SINClient>)client localNotificationForIncomingCall:(id<SINCall>)call {
SINLocalNotification *notification = [[SINLocalNotification alloc] init];
NSArray * ansAr = #[#"رد",#"Answer"];
NSArray * MsgAr = #[[NSString stringWithFormat:#"مكالمة لم يرد عليها من %#", [call remoteUserId]],[NSString stringWithFormat:#"Incoming call from %#", [call remoteUserId]]];
notification.alertAction = ansAr[self.languageID];
notification.alertBody = MsgAr[self.languageID];
return notification;
}
- (void)client:(id<SINClient>)client willReceiveIncomingCall:(id<SINCall>)call {
[self.callKitProvider reportNewIncomingCall:call];
}
These is the code , Please help me if I forgot anything.
I checked the credentials.token is not null.
Thank you for your help.

When you setup the Sinch managed push with the code below:
self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
self.push.delegate = self;
[self.push setDesiredPushTypeAutomatically];
The Sinch SDK will automatically do all the PushKit registration for you. So step 3 and 4 in your description is not necessary and should not be there. Part of the code in step 2 is not needed as well. Please take a look at the Sinch CallKit sample app from the SDK download package, and refer to the implementation of that App.
Below is a demo video made with the 3.12.4 Sinch SDK CallKit Sample App without any tweak, the device used in the demo is an iPhone7 running iOS 11, it gets the incoming call in background, killed and lockscreen mode:
Sinch CallKit Sample App Demo Video
Also, note that callKit only works with VoIP push, have you uploaded the right type of push certificate to Sinch Portal?

When you force kill an app apple wont wake the app for VoIP push, if you just have in background or reboot the phone apple will wake it up. Annoying, but that's apple

Related

Sinch VOIP calls between two different apps with different bundle IDs

I am trying to establish voip call through two different apps. Lets assume one is seller and another is customer. Seller app can only call, and customer app can only receive call. I have setup two apps with sinch applicationKey, secret, userID etc. As I want to receive call in customer app, I have generated VOIP certificate in Apple Dev Account for customer app's bundle id. And I have uploaded that certificate(p12) in Sinch Dashboard. I am using Managed Push in customer app.
But I am unable to receive push or calls in customer app.
I tried changing the bundle id of the two apps. When I keep the bundle id same for the two apps, it works like charm.
My question is, How can I make voip calls between two different apps with different bundle ids?
Here is my AppDelegate.m file codes, which works as it should when the bundle id is same:
#import "SINCallKitProvider.h"
#import "CallViewController.h"
#interface AppDelegate () <SINClientDelegate, SINCallClientDelegate, SINManagedPushDelegate>
#property (nonatomic, readwrite, strong) id<SINManagedPush> push;
#property (nonatomic, readwrite, strong) SINCallKitProvider *callKitProvider;
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSLog(#"didFinishLaunchingWithOptions:");
[Sinch setLogCallback:^(SINLogSeverity severity, NSString *area, NSString *message, NSDate *timestamp) {
NSLog(#"[%#] %#", area, message);
}];
self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
self.push.delegate = self;
[self.push setDesiredPushType:SINPushTypeVoIP];
self.callKitProvider = [[SINCallKitProvider alloc] init];
void (^onUserDidLogin)(NSString *) = ^(NSString *userId) {
[self initSinchClientWithUserId:userId];
};
[[NSNotificationCenter defaultCenter]
addObserverForName:#"UserDidLoginNotification"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
NSString *userId = note.userInfo[#"userId"];
[[NSUserDefaults standardUserDefaults] setObject:userId forKey:#"userId"];
[[NSUserDefaults standardUserDefaults] synchronize];
onUserDidLogin(userId);
}];
[[NSNotificationCenter defaultCenter] addObserverForName:#"UserDidLogoutNotification"
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
_client = nil;
}];
return YES;
}
- (void)applicationWillEnterForeground:(UIApplication *)application {
id<SINCall> call = [_callKitProvider currentEstablishedCall];
// If there is one established call, show the callView of the current call when
// the App is brought to foreground. This is mainly to handle the UI transition
// when clicking the App icon on the lockscreen CallKit UI.
if (call) {
UIViewController *top = self.window.rootViewController;
while (top.presentedViewController) {
top = top.presentedViewController;
}
// When entering the application via the App button on the CallKit lockscreen,
// and unlocking the device by PIN code/Touch ID, applicationWillEnterForeground:
// will be invoked twice, and "top" will be CallViewController already after
// the first invocation.
if (![top isMemberOfClass:[CallViewController class]]) {
[top performSegueWithIdentifier:#"callView" sender:call];
}
}
}
#pragma mark -
- (void)initSinchClientWithUserId:(NSString *)userId {
if (!_client) {
_client = [Sinch clientWithApplicationKey:#"<My key>"
applicationSecret:#"<My secret>"
environmentHost:#"clientapi.sinch.com"
userId:userId];
_client.delegate = self;
_client.callClient.delegate = self;
[_client setSupportCalling:YES];
[_client enableManagedPushNotifications];
_callKitProvider.client = _client;
[_client start];
// [_client startListeningOnActiveConnection];
}
}
- (void)handleRemoteNotification:(NSDictionary *)userInfo {
if (!_client) {
NSString *userId = [[NSUserDefaults standardUserDefaults] objectForKey:#"userId"];
if (userId) {
[self initSinchClientWithUserId:userId];
}
}
[self.client relayRemotePushNotification:userInfo];
}
#pragma mark - SINManagedPushDelegate
- (void)managedPush:(id<SINManagedPush>)managedPush
didReceiveIncomingPushWithPayload:(NSDictionary *)payload
forType:(NSString *)pushType {
NSLog(#"didReceiveIncomingPushWithPayload: %#", payload.description);
// Since iOS 13 the application must report an incoming call to CallKit if a
// VoIP push notification was used, and this must be done within the same run
// loop as the push is received (i.e. GCD async dispatch must not be used).
// See https://developer.apple.com/documentation/pushkit/pkpushregistrydelegate/2875784-pushregistry .
[self.callKitProvider didReceivePushWithPayload:payload];
dispatch_async(dispatch_get_main_queue(), ^{
[self handleRemoteNotification:payload];
[self.push didCompleteProcessingPushPayload:payload];
});
}
#pragma mark - SINCallClientDelegate
- (void)client:(id<SINCallClient>)client didReceiveIncomingCall:(id<SINCall>)call {
// Find MainViewController and present CallViewController from it.
UIViewController *top = self.window.rootViewController;
while (top.presentedViewController) {
top = top.presentedViewController;
}
[top performSegueWithIdentifier:#"callView" sender:call];
}
- (void)client:(id<SINClient>)client willReceiveIncomingCall:(id<SINCall>)call {
[self.callKitProvider willReceiveIncomingCall:call];
}
#pragma mark - SINClientDelegate
- (void)clientDidStart:(id<SINClient>)client {
NSLog(#"Sinch client started successfully (version: %#)", [Sinch version]);
}
- (void)clientDidFail:(id<SINClient>)client error:(NSError *)error {
NSLog(#"Sinch client error: %#", [error localizedDescription]);
}
#end

After integrating OneSignal Cordova SDK my App delegate methods are not called for UNUserNotificationCenterDelegate

#import "AppDelegate.h"
#import <UserNotifications/UserNotifications.h>
#import "MainViewController.h"
#interface AppDelegate () <UNUserNotificationCenterDelegate>
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication*)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions
{
self.viewController = [[MainViewController alloc] init];
[self registerForNotification];
return [super application:application didFinishLaunchingWithOptions:launchOptions];
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification*)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
// This method are not getting called
completionHandler(UNNotificationPresentationOptionAlert|UNNotificationPresentationOptionBadge|UNNotificationPresentationOptionSound);
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(nonnull UNNotificationResponse* )response withCompletionHandler:(nonnull void (^)(void))completionHandler {
// This method are not getting called
NSDictionary *userInfo = response.notification.request.content.userInfo;
completionHandler();
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
NSLog(#"DEVICE_TOKEN :: %#", deviceToken);
const unsigned *tokenBytes = [deviceToken bytes];
NSString *hexToken = [NSString stringWithFormat:#"%08x%08x%08x%08x%08x%08x%08x%08x",
ntohl(tokenBytes[0]), ntohl(tokenBytes[1]), ntohl(tokenBytes[2]),
ntohl(tokenBytes[3]), ntohl(tokenBytes[4]), ntohl(tokenBytes[5]),
ntohl(tokenBytes[6]), ntohl(tokenBytes[7])];
NSString *apnDeviceToken = hexToken;
NSLog(#"APN_DEVICE_TOKEN :: %#", apnDeviceToken);
}
-(void)registerForNotification
{
if(#available(iOS 10.0, *))
{
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error)
{
if(!error)
{
dispatch_async(dispatch_get_main_queue(), ^ {
[[UIApplication sharedApplication] registerForRemoteNotifications]; // required to get the app to do anything at all about push notifications
NSLog(#"Push registration success." );
});
}
else
{
NSLog(#"Push registration FAILED" );
NSLog(#"ERROR: %# - %#", error.localizedFailureReason, error.localizedDescription );
NSLog(#"SUGGESTIONS: %# - %#", error.localizedRecoveryOptions, error.localizedRecoverySuggestion );
}
}];
}
}
#end
The didReceiveNotificationResponse and willPresentNotification did not trigger. I'm not able to handle Other APNS notification which is not related to one signal Cordova plugin SDK notification.
Is there any way that my app delegate methods for UserNotifications delegate methods will trigger in Cordova ios when one signal plugin used?
I suspect that due to swizzling the app delegate methods by one signal callbacks are not triggered in the original Appdelegate file.
Please help on this if we have any other way to get my app delegate
UserNotifications delegate methods trigger.
As one signal uses the static frameworks in Cordova there is no way to change the code inside the plugin.
This is the one signal plugin for Cordova github https://github.com/OneSignal/OneSignal-Cordova-SDK

Sinch SDK with VoIP, PushKit, CallKit

I integrated Sinch sdk into my projects with VoIP, PushKit, CallKit. Everything is working fine. But when app is not running in device A and someone(Device B) is calling to it then sometimes in device A I am getting notification with text SIN_INCOMING_CALL . I don't know from where it is coming. But my problem is, I want to open default call screen of iOS device. Sometime it is being opened and sometimes it show notification with this text.
My Appdelegate has following code.
#interface AppDelegate() <SINClientDelegate, SINCallClientDelegate, SINManagedPushDelegate, SINCallDelegate>
#property (nonatomic, readwrite, strong) id<SINManagedPush> push;
#property (strong, nonatomic) id<SINClient> sinchClient;
#property (nonatomic, readwrite, strong) SINCallKitProvider *callKitProvider;
#end
#implementation AppDelegate
- (void)applicationWillEnterForeground:(UIApplication *)application
{
id<SINCall> call = [self.callKitProvider currentEstablishedCall];
if (call) {
//Show call view controller and pass call
}
}
#pragma mark - Remote Notification
- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings
{
if (notificationSettings.types != UIUserNotificationTypeNone) { [application registerForRemoteNotifications]; }
}
- (void)application:(UIApplication*)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData*)deviceToken
{
NSString *newToken = deviceToken.description;
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:#" " withString:#""];
[self.push application:application didRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
NSLog(#"My token is: %#", newToken);
//get previously initiated Sinch client
if (!self.sinchClient) { [self initSinchCallConfig]; }
id<SINClient> client = [self sinchClient];
[client registerPushNotificationData:deviceToken];
}
- (void)application:(UIApplication*)application didFailToRegisterForRemoteNotificationsWithError:(NSError*)error
{
NSLog(#"Failed to get token, error: %#", error);
[obj_SharedModel setUDID:#""]; //Statuc Device Id just for testing purpose from simulator.
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
[self.push application:application didReceiveRemoteNotification:userInfo];
}
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo fetchCompletionHandler:(void (^)(UIBackgroundFetchResult))completionHandler
{
completionHandler(UIBackgroundFetchResultNewData);
}
- (void)registerForPushNotifications
{
UIApplication *application = [UIApplication sharedApplication];
if (IS_OS_10_BELOW) {
UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:(UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound) categories:nil];
[application registerUserNotificationSettings:settings];
}
else {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){ dispatch_async(dispatch_get_main_queue(), ^{ [[UIApplication sharedApplication] registerForRemoteNotifications]; }); }
}];
}
//register for VoIP push
PKPushRegistry *voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
voipRegistry.delegate = self;
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
self.push.delegate = self;
[self.push setDesiredPushTypeAutomatically];
[self.push registerUserNotificationSettings];
}
- (void)unRegisterForPushNotifications
{
[[UIApplication sharedApplication] unregisterForRemoteNotifications];
[self.sinchClient unregisterPushNotificationDeviceToken];
}
#pragma mark - IOS 10 UP - UNUserNotificationCenter
//Called when a notification is delivered to a foreground app.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler {
NSLog(#"User Info : %#",notification.request.content.userInfo);
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}
//Called to let your app know which action was selected by the user for a given notification.
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)(void))completionHandler {
completionHandler();
}
#pragma mark - VoIP remote Notifications
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type {
NSString *newToken = credentials.token.description;
newToken = [newToken stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:#"<>"]];
newToken = [newToken stringByReplacingOccurrencesOfString:#" " withString:#""];
NSLog(#"VoIP Tokenp is: %#", newToken);
}
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type {
NSDictionary *dictPayload = payload.dictionaryPayload;
if ([dictPayload sin_isSinchPushPayload]) {
if (!self.sinchClient) { [self initSinchCallConfig]; }
[self.sinchClient relayRemotePushNotification:dictPayload];
/*
{"aps":{"alert":{"loc-key" : "SIN_INCOMING_CALL"}},"sin" :"ASDAS" }
*/
}
else {
}
}
- (void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(NSString *)type { }
#pragma mark - SINClient Method
- (void)initSinchCallConfig
{
// Instantiate a Sinch client object
if (!self.sinchClient && [stLoginUserName length]) {
self.sinchClient = [Sinch clientWithApplicationKey:#"dea827c1-1208-45a6-b510-5d1f277d9607" applicationSecret:#"AgxDpf/4X0OrLx1GXv6Quw==" environmentHost:#"sandbox.sinch.com" userId:stLoginUserName];
self.sinchClient.delegate = self;
self.sinchClient.callClient.delegate = self; //for incomming call
[self.sinchClient setSupportCalling:YES];
[self.sinchClient setSupportPushNotifications:YES];
[self.sinchClient setPushNotificationDisplayName:MSG_TITLE];
[self.sinchClient enableManagedPushNotifications];
[self.sinchClient start];
[self.sinchClient startListeningOnActiveConnection];
self.callKitProvider = [[SINCallKitProvider alloc] initWithClient:self.sinchClient];
}
}
#pragma mark - SINClient Delegate
- (void)clientDidStart:(id<SINClient>)client {
NSLog(#"Sinch client started successfully (version: %#)", [Sinch version]);
}
- (void)clientDidFail:(id<SINClient>)client error:(NSError *)error {
NSLog(#"Sinch client error: %#", [error localizedDescription]);
}
- (void)client:(id<SINClient>)client logMessage:(NSString *)message area:(NSString *)area severity:(SINLogSeverity)severity timestamp:(NSDate *)timestamp {
NSLog(#"%#", message);
}
#pragma mark - SINCallClient Delegate
- (void)client:(id<SINCallClient>)client didReceiveIncomingCall:(id<SINCall>)call {
NSLog(#"didReceiveIncomingCall");
CallViewController *callVC = [[CallViewController alloc] initWithNibName:#"CallViewController" bundle:nil];
callVC.call = call;
AppNavigationController *nav = [[AppNavigationController alloc] initWithRootViewController:callVC];
[self.navigationController presentViewController:nav animated:YES completion:nil];
if (call.details.applicationStateWhenReceived == UIApplicationStateActive) { }
else { [callVC btnAcceptCallAction]; }
}
- (void)client:(id<SINClient>)client willReceiveIncomingCall:(id<SINCall>)call {
[self.callKitProvider reportNewIncomingCall:call];
call.delegate = self;
}
#pragma mark - SINManagedPush Delegate
- (void)managedPush:(id<SINManagedPush>)unused didReceiveIncomingPushWithPayload:(NSDictionary *)payload forType:(NSString *)pushType {
if (!self.sinchClient) { [self initSinchCallConfig]; }
[self.sinchClient relayRemotePushNotification:payload];
}
- (void)call:(id<SINCall>)call shouldSendPushNotifications:(NSArray *) pushPairs {
NSLog(#"shouldSendPushNotifications");
}
#pragma mark - SINCall Delegate
- (void)callDidProgress:(id<SINCall>)call {
}
- (void)callDidEstablish:(id<SINCall>)call {
}
- (void)callDidEnd:(id<SINCall>)call { [[self callKitProvider] reportCallEnded:call]; }
#end

Pushkit with Sinch VOIP not working with pushkit

I am trying to implement App-to-App calling with Sinch in my IOS app. I have implemented Pushkit in my iOS app with Sinch but the push notification is not working when the app is in background.
I have two questions.
Do I need another web service to send push notification to my app for incoming app separately or Sinch handles it itself.
If it does handle itself then what am I missing in my code.
#import "AppDelegate.h"
#interface AppDelegate ()
#end
#implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
UIUserNotificationSettings* notificationSettings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeAlert | UIUserNotificationTypeBadge | UIUserNotificationTypeSound categories:nil];
[[UIApplication sharedApplication] registerUserNotificationSettings:notificationSettings];
[self handleLocalNotification:[launchOptions objectForKey:UIApplicationLaunchOptionsLocalNotificationKey]];
self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
self.push.delegate = self;
[self.push setDesiredPushTypeAutomatically];
[self.push registerUserNotificationSettings];
return YES;
}
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary *)options {
return [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]];
}
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
return [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
- (id<SINClient>)client {
return _sinchClient;
}
-(void)clientDidFail:(id<SINClient>)client error:(NSError *)error{
NSLog(#"fail");
}
-(void)clientDidStart:(id<SINClient>)client{
NSLog(#"Start");
[self voipRegistration];
}
- (void)client:(id<SINClient>)client
logMessage:(NSString *)message
area:(NSString *)area
severity:(SINLogSeverity)severity
timestamp:(NSDate *)timestamp {
// If you want all messages remove the if statement
if (severity == SINLogSeverityCritical) {
NSLog(#"%#", message);
}
}
- (void)initSinchClientWithUserId:(NSString *)userId {
if (!_sinchClient) {
_sinchClient = [Sinch clientWithApplicationKey:#"<my-key>"
applicationSecret:#"<my-secret>"
environmentHost:#"sandbox.sinch.com"
userId:userId];
_sinchClient.delegate = self;
[_sinchClient setSupportCalling:YES];
[_sinchClient startListeningOnActiveConnection];
[_sinchClient enableManagedPushNotifications];
[_sinchClient start];
}
}
- (void)handleLocalNotification:(UILocalNotification *)notification {
if (notification) {
id<SINNotificationResult> result = [self.sinchClient relayLocalNotification:notification];
if ([result isCall] && [[result callResult] isTimedOut]) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:#"Missed call"
message:[NSString stringWithFormat:#"Missed call from %#", [[result callResult] remoteUserId]]
delegate:nil
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil];
[alert show];
}
}
}
-(void)voipRegistration
{
PKPushRegistry* voipRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
voipRegistry.delegate = self;
voipRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
}
-(void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials:(PKPushCredentials *)credentials forType:(NSString *)type
{
[_sinchClient registerPushNotificationData:credentials.token];
}
-(void)pushRegistry:(PKPushRegistry *)registry didInvalidatePushTokenForType:(PKPushType)type{
NSLog(#"invalidated");
}
-(void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType: (NSString *)type
{
//notify
NSDictionary* dic = payload.dictionaryPayload;
NSString* sinchinfo = [dic objectForKey:#"sin"];
UILocalNotification* notif = [[UILocalNotification alloc] init];
notif.alertBody = #"incoming call";
[[UIApplication sharedApplication] presentLocalNotificationNow:notif];
if (sinchinfo == nil)
return;
dispatch_async(dispatch_get_main_queue(), ^{
[_sinchClient relayRemotePushNotificationPayload:sinchinfo];
});
}
If you integrated Pushkit and Sinch then push notification may can't catch on PushKit's delegate function - didReceiveIncomingPushWithPayload. But you can get push notification on SINManagedPushDelegate's function - didReceiveIncomingPushWithPayload.
Push notification is not coming but you can get incoming call event on there when app is in background. You can trigger local notification if app is in background to let user incoming call know.
Hope that would be helpful for you.

Integrate Box IOS sdk in my ios project

I'm trying to integrate BOX V2 IOS SDk on my ios project , the integration is fine, but when I try to login , and after I enter my username and password and granted the access , I get a white screen , and the boxAPIAuthenticationDidSucceed method is not called , her is my code
the connexion Method :
-(void) connectToBox {
[BoxSDK sharedSDK].OAuth2Session.clientID = #"my-client-id";
[BoxSDK sharedSDK].OAuth2Session.clientSecret = #"my-client-secret";
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(boxAPIAuthenticationDidSucceed:)
name:BoxOAuth2SessionDidBecomeAuthenticatedNotification
object:[BoxSDK sharedSDK].OAuth2Session];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(boxAPIAuthenticationDidFail:)
name:BoxOAuth2SessionDidReceiveAuthenticationErrorNotification
object:[BoxSDK sharedSDK].OAuth2Session];
self.LoginCotroller = [[BoxAuthorizationViewController alloc] initWithAuthorizationURL:authorizationURL redirectURI:redirectURI];
[self presentViewController:self.LoginCotroller animated:YES completion:nil];
}
and I implement the two methods :
- (void)boxAPIAuthenticationDidSucceed:(NSNotification *)notification;
- (void)boxAPIAuthenticationDidFail:(NSNotification *)notification;
and the notifications methods :
#pragma mark - Handle OAuth2 session notifications
- (void)boxAPIAuthenticationDidSucceed:(NSNotification *)notification
{
BoxOAuth2Session *session = (BoxOAuth2Session *) notification.object;
NSLog(#"Received OAuth2 successfully authenticated notification");
NSLog(#"Access token (%#) expires at %#", session.accessToken, session.accessTokenExpiration);
NSLog(#"Refresh token (%#)", session.refreshToken);
dispatch_sync(dispatch_get_main_queue(), ^{
[self.LoginCotroller dismissViewControllerAnimated:YES completion:nil];
});
}
- (void)boxAPIAuthenticationDidFail:(NSNotification *)notification
{
NSLog(#"Received OAuth2 failed authenticated notification");
NSString *oauth2Error = [[notification userInfo] valueForKey:BoxOAuth2AuthenticationErrorKey];
NSLog(#"Authentication error (%#)", oauth2Error);
dispatch_sync(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:YES completion:nil];
});
}
I dont know what wrong with my code.So if any one can help.Thanks
I'd suggest adding your controller as an observer for BoxOAuth2SessionDidRefreshTokensNotification as well to call boxAPIAuthenticationDidSucceed: method. BoxOAuth2SessionDidRefreshTokensNotification is posted when a new access-token is created/refresed.

Resources