Avinay Kumar
Avinay Kumar

Reputation: 163

Sinch - Call is not getting initiated in closed state

Cannot initiate call if app is in closed state in iPhone(iOS 10).

I am using push kit service for call. If app is in background, i am receiving call but if app is in closed state then notification is received from server but call is not getting initiated.

I have checked _client object is not nil.

I am initializing SINCH client by below code ::

- (void)initSinchClientWithUserId:(NSString *)userId
{    
    if (!_client) {

        if(userId.length <= 0)
            return;


        _client = [Sinch clientWithApplicationKey:SINCH_APP_KEY
                                      environmentHost:SINCH_ENVIRONMENT_HOST
                                               userId:userId];

        _client.delegate = self;
        _client.callClient.delegate = self;
        [_client setSupportCalling:YES];

        [_client setSupportActiveConnectionInBackground:YES];

        [_client setSupportPushNotifications:YES];
        [_client start];

        [_client startListeningOnActiveConnection];

    }

}

Below is code in didReceiveIncomingPushWithPayload method

-(void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(NSString *)type
{

    NSDictionary* dic = payload.dictionaryPayload

    if([dic.allKeys containsObject:@"sin"])
    {
        NSString* sinchinfo = [dic objectForKey:@"sin"];

        if (sinchinfo == nil)
            return;

        dispatch_async(dispatch_get_main_queue(), ^{
            [_client relayRemotePushNotificationPayload:sinchinfo];
        });
    }
}

Note :: I have check in iOS 9, it is working properly as below method is getting called

- (SINLocalNotification *)client:(id<SINClient>)client localNotificationForIncomingCall:(id<SINCall>)call
{

}

Upvotes: 1

Views: 686

Answers (1)

Vishal Sonawane
Vishal Sonawane

Reputation: 2693

Try to use this code for Sinch initialisation:

1. Declare property in your viewController

@property (nonatomic, readwrite, strong) id<SINManagedPush> push;

2. Add Below code in AppDelegate (didFinishLaunchingWithOptions)

//Sinch managed Push Notifications
    self.push = [Sinch managedPushWithAPSEnvironment:SINAPSEnvironmentAutomatic];
    self.push.delegate = self;
    [self.push setDesiredPushTypeAutomatically];
    //Sinch Remote notifications
    id config = [[SinchService configWithApplicationKey:SINCH_KEY
                                      applicationSecret:SINCH_SECRET
                                        environmentHost:SINCH_HOST]
                 pushNotificationsWithEnvironment:SINAPSEnvironmentProduction];

    id<SINService> sinch = [SinchService serviceWithConfig:config];
    sinch.delegate = self;
    sinch.callClient.delegate = self;

3. Finally

- (void)initSinchClientWithUserId:(NSString *)userId {
    if (!_client) {
        _client = [Sinch clientWithApplicationKey:SINCH_KEY
                                applicationSecret:SINCH_SECRET
                                  environmentHost:SINCH_HOST
                                           userId:userId];

        _client.delegate = self;
        _client.callClient.delegate = self;
        [_client setSupportCalling:YES];
        [_client enableManagedPushNotifications];
        [_client start];
    }
}

Upvotes: 1

Related Questions