iOS Callkit:CXProvider 启动后立即重置

iOS Callkit: CXProvider resets immediately after starting

我正在将现有的 VoIP 应用程序转换为 Callkit。我有很多代码,但不知何故,当我初始化 CXProvider 时,它将调用 providerDidBegin,然后立即调用 providerDidReset。它没有给出原因。之后我无法注册我的拨出 phone 电话之一,因为我的提供商未激活。

我已经尝试查看证书、设置等,但基本上我不需要比我的 VoIP 应用程序看起来更多的东西。

CallKit调用重置方法的调用如下:

CallKit`__42-[CXProvider handleConnectionInterruption]_block_invoke:

当我深入挖掘它的来源时,它与 NSXPCConnection 相关。这是什么连接,我需要如何设置它?

当然没有中断连接。

这是我初始化代理的方式:

- (id)init {
    self = [super init];

    self.configuration = [[ProviderConfiguration alloc] init];
    self.provider = [[CXProvider alloc] initWithConfiguration:self.configuration];

    [self.provider setDelegate:self queue:dispatch_get_main_queue()];

    return self;
}

这是配置的样子:

- (instancetype)init {
    self = [super initWithLocalizedName:@"MyCompany"];

    self.supportsVideo = NO;
    self.maximumCallsPerCallGroup = 1;
    self.supportedHandleTypes = [[NSSet alloc] initWithObjects:[NSNumber numberWithInt:(int)CXHandleTypePhoneNumber], nil];
    self.maximumCallGroups = 1;
    self.maximumCallsPerCallGroup = 5;


    return self;
}

两个回调都实现了:

- (void)providerDidBegin:(CXProvider *)provider {
    NSLog(@"Begun");
}

- (void)providerDidReset:(CXProvider *)provider {
    NSLog(@"Reset");
}

不知何故这些行是问题所在:

self.configuration = [[ProviderConfiguration alloc] init];
self.provider = [[CXProvider alloc] initWithConfiguration:self.configuration];

它在调用 init 之前存储在 self.configuration 中。通过将相同的代码内嵌到那里,它起作用了。

CXProviderConfiguration *configuration = [[CXProviderConfiguration alloc] initWithLocalizedName:@"MyCompany"];

configuration.supportsVideo = NO;
configuration.supportedHandleTypes = [[NSSet alloc] initWithObjects:[NSNumber numberWithInt:(int)CXHandleTypePhoneNumber], nil];
configuration.maximumCallGroups = 1;
configuration.maximumCallsPerCallGroup = 5;
self.provider = [[CXProvider alloc] initWithConfiguration:configuration];

在我的案例中,同样的问题是由于 Info.plist 文件

中缺少 VOIP 后台模式造成的
<key>UIBackgroundModes</key>
<array>
    <string>audio</string>
    <string>voip</string>
</array>

XCode 9 不允许使用“功能”选项卡设置此后台模式,原因不明。

确保您使用有效的非空 UUID 调用 reportNewIncomingCallWithUUID:update:completion。 Apple 当前的实现调用完成没有错误,但没有显示调用屏幕

我在模拟器上有同样的行为。 在设备上没问题。

您不能使用 providerDidBegin 来处理呼叫,因为它用于标识您的 class 实例 ProviderDelegateCXProviderDelegate 实例的开头。要进行正确的管理,您必须创建可以为您执行此操作的辅助 classes。

请参阅以下来自 WWDC 2016 的示例: https://github.com/Lax/Learn-iOS-Swift-by-Examples/tree/master/Speakerbox