如果应用程序在iPhone(iOS 10)中处于关闭状态,则无法发起 call 。
我正在使用推包服务进行通话。
如果应用程序处于后台,则我正在接听电话,但是如果应用程序处于关闭状态,则从服务器接收到通知,但未启动 call 。
我检查了 _client 对象不是零。
我通过以下代码初始化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/