我试图用最简单的代码模拟一个调用(juste用于测试目的)。这是我使用的代码:
var handleTypes = new[] { (NSNumber)(int)CXHandleType.PhoneNumber };
CXProviderConfiguration config = new CXProviderConfiguration("Test")
{
MaximumCallsPerCallGroup = 1,
SupportedHandleTypes = new NSSet<NSNumber>(handleTypes)
};
CXProvider provider = new CXProvider(config);
provider.SetDelegate(new ProviderDelegate(), null);
CXCallController controller = new CXCallController();
CXHandle handle = new CXHandle(CXHandleType.Generic, "test");
CXStartCallAction action = new CXStartCallAction(new NSUuid(), handle);
CXTransaction transaction = new CXTransaction(action);
controller.RequestTransaction(transaction, (error) =>
{
Console.WriteLine(error);
});
我的ProviderDelegate
看起来像这样:
class ProviderDelegate : CXProviderDelegate
{
public override void DidReset(CXProvider provider)
{
}
public override void PerformAnswerCallAction(CXProvider provider, CXAnswerCallAction action)
{
base.PerformAnswerCallAction(provider, action);
}
public override void PerformEndCallAction(CXProvider provider, CXEndCallAction action)
{
base.PerformEndCallAction(provider, action);
}
public override void PerformStartCallAction(CXProvider provider, CXStartCallAction action)
{
base.PerformStartCallAction(provider, action);
}
public override void PerformSetHeldCallAction(CXProvider provider, CXSetHeldCallAction action)
{
base.PerformSetHeldCallAction(provider, action);
}
public override void TimedOutPerformingAction(CXProvider provider, CXAction action)
{
base.TimedOutPerformingAction(provider, action);
}
public override void DidActivateAudioSession(CXProvider provider, AVAudioSession audioSession)
{
base.DidActivateAudioSession(provider, audioSession);
}
public override void DidDeactivateAudioSession(CXProvider provider, AVAudioSession audioSession)
{
base.DidDeactivateAudioSession(provider, audioSession);
}
public void ReportIncomingCall(NSUuid uuid, string handle)
{
}
}
同样,我只是想在屏幕上显示某些内容。 ProviderDelegate
在每个方法中都有断点,所以我知道它们何时被调用。
当我运行代码时,我会在我的(error)=>
委托中回复,错误为Couldn’t communicate with a helper application.
NSCocoaErrorDomain:4097
。
注意:我已将VoIP权利添加到我的应用中,重新安装了所有内容,运行了最新版本的macOS以及最新的Xcode。