Sinch - 呼叫未在关闭状态下启动

时间:2017-01-05 10:17:24

标签: ios objective-c ios10 voip sinch

如果应用程序在iPhone(iOS 10)中处于关闭状态,则无法启动呼叫。

我正在使用推送套件服务进行通话。 如果应用程序在后台,我正在接听电话,但如果应用程序处于关闭状态,则会从服务器收到通知,但呼叫未启动。

我检查过 _client 对象不是nil。

我正在通过以下代码::

初始化SINCH客户端
- (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];

    }

}

以下是 didReceiveIncomingPushWithPayload 方法中的代码

-(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];
        });
    }
}

注意::我已经在iOS 9中检查,它正常工作,因为以下方法被称为

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

}

1 个答案:

答案 0 :(得分:1)

尝试将此代码用于Sinch初始化:

1。viewController

中声明属性
@property (nonatomic, readwrite, strong) id<SINManagedPush> push;

2。AppDelegatedidFinishLaunchingWithOptions

中添加以下代码
//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。最后

- (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];
    }
}