【发布时间】:2019-09-26 12:41:55
【问题描述】:
我已经在 iOS 中使用 VoIP PushKit 实现了 CallKit 进行音频和视频通话,它在 iOS 12 和之前的版本中运行良好,并且在 iOS 13 和 13.1 中运行正常。
但它在两种情况下都失败了:
1) 我们的应用程序处于前台状态。当移动电话正在运行并且收到 VoIP 推送时,呼叫套件来电屏幕会显示 5 到 10 秒,然后移动电话和 VOIP 呼叫都失败并显示“呼叫失败”警报。
2) 我们的应用程序处于后台或已终止状态。当蜂窝电话正在运行并收到 VoIP 推送时,蜂窝电话和 VOIP 电话都将失败,并显示“呼叫失败”警报。这次没有来电界面显示。
我在这里展示我的代码:
- (void)registerAppForVOIPPush {
PKPushRegistry *pushRegistry = [[PKPushRegistry alloc] initWithQueue:dispatch_get_main_queue()];
pushRegistry.delegate = self;
pushRegistry.desiredPushTypes = [NSSet setWithObject:PKPushTypeVoIP];
}
然后推送代表
#pragma mark PKPushRegistryDelegate ----
- (void)pushRegistry:(PKPushRegistry *)registry didUpdatePushCredentials: (PKPushCredentials *)credentials forType:(NSString *)type {
NSString *newToken = [self hexadecimalStringFromData:credentials.token];
//Make a note of this token to a server to send VOIP for a particular device
NSLog(@"VOIP token ::: %@", newToken);
_voipToken = newToken;
}
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type {
//available(iOS, introduced: 8.0, deprecated: 11.0)
[self pushRegistryDidReceivedPushWithPayload:payload forType:type withCompletionHandler:NULL];
}
- (void)pushRegistry:(PKPushRegistry *)registry didReceiveIncomingPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {
//available(iOS 11.0, *)
[self pushRegistryDidReceivedPushWithPayload:payload forType:type withCompletionHandler:completion];
}
- (void)pushRegistryDidReceivedPushWithPayload:(PKPushPayload *)payload forType:(PKPushType)type withCompletionHandler:(void (^)(void))completion {
//Call kit configration
CXProviderConfiguration *providerConfig = [[CXProviderConfiguration alloc] initWithLocalizedName:@"my app Call"];
providerConfig.supportsVideo = NO;
providerConfig.maximumCallGroups = 1;
providerConfig.maximumCallsPerCallGroup = 1;
providerConfig.supportedHandleTypes = [[NSSet alloc] initWithObjects:[NSNumber numberWithInteger:CXHandleTypeGeneric], nil];
providerConfig.iconTemplateImageData = UIImagePNGRepresentation([UIImage imageNamed:@"IconMask"]);
CXProvider *provider = [[CXProvider alloc] initWithConfiguration:providerConfig];
[provider setDelegate:self queue:nil];
//generate token
NSUUID *callbackUUIDToken = [NSUUID UUID];
//Display callkit
NSString *uniqueIdentifier = @"Max test";
CXCallUpdate *update = [[CXCallUpdate alloc] init];
update.remoteHandle = [[CXHandle alloc] initWithType:CXHandleTypeGeneric value:uniqueIdentifier];
update.supportsGrouping = FALSE;
update.supportsUngrouping = FALSE;
update.supportsHolding = FALSE;
update.localizedCallerName = uniqueIdentifier;
update.hasVideo = NO;
[provider reportNewIncomingCallWithUUID:callbackUUIDToken update:update completion:^(NSError * _Nullable error) {
NSLog(@"reportNewIncomingCallWithUUID error: %@",error);
}];
if (completion) {
dispatch_async(dispatch_get_main_queue(), ^{
completion();
});
}
}
我已经完美实现了CXProvider委托方法
- (void)provider:(CXProvider *)provider performAnswerCallAction:(CXAnswerCallAction *)action{
[action fulfill];
}
- (void)provider:(CXProvider *)provider performEndCallAction:(CXEndCallAction *)action{
[action fulfill];
}
还管理其他委托方法来管理调用和所有内容,并且在所有条件下都能完美运行。
我已经使用 Google Duo、Whatsapp 和 FaceTime 等其他应用程序检查了这两种情况,它可以正确显示 CallKit 而不会失败,但在我的应用程序中却失败了。我不知道它在哪里失败。
所以,对于 iOS 13 及更高版本,我有这 2 个声明的问题。任何帮助将不胜感激。 谢谢。
【问题讨论】:
标签: objective-c voip ios13 callkit pushkit