gpt4 book ai didi

ios - Sinch - 调用未在关闭状态下启动

转载 作者:行者123 更新时间:2023-11-29 11:50:08 24 4
gpt4 key购买 nike

如果应用程序在 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
{

}

最佳答案

尝试使用此代码进行 Sinch 初始化:

1. 在您的 viewController

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

2.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.最后

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

关于ios - Sinch - 调用未在关闭状态下启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41482352/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com