CallKit Call hasConnected始终返回true



我正在开发VOIP应用程序,并在iOS上实现CallKit。

通过此链接:https://developer.apple.com/documentation/callkit/cxcall/1649013-hasconnected?language=objc

当调用者和被调用者都可以启动时,调用被视为已连接沟通。

这在这里意味着什么?这是否意味着必须启动WebRTC或其他音频/视频流才能返回true?或者这是否意味着,如果用户按下接受呼叫按钮,它就被视为已连接?

我有以下代码来检查呼叫的状态,它总是返回true或我给出的任何解决方案:

CXCallObserver *callObserver = [[CXCallObserver alloc] init];
NSUUID *uuid = [[NSUUID alloc] initWithUUIDString:uuidString];

BOOL _mybool = false;

for(CXCall *call in callObserver.calls){

if([call.UUID isEqual:[[NSUUID alloc] initWithUUIDString:uuidString]] && !call.hasConnected){
_mybool = true;
resolve(@"true");
}
}

if(!_mybool){
reject(false, false, false);
}

在代码中,您在错误的位置检查调用状态。这会在执行过程中产生问题。

你必须先用call-it设置callobserver。你已经正确地完成了。但DetectOutgoingCall 需要一个标志

func setupCallObserverWithCallKit() {

if #available(iOS 10.0, *) {
didDetectOutgoingCall = false
if callObserver == nil {
callObserver = CXCallObserver()
callObserver!.setDelegate(self, queue: nil)
}

}
}

然后在callObserver中编写您的逻辑。

@available(iOS 10.0, *)
func callObserver(_ callObserver: CXCallObserver, callChanged call: CXCall) {

if call.isOutgoing && !didDetectOutgoingCall {
didDetectOutgoingCall = true
// "Call button pressed"
}

if call.hasEnded   == true && call.isOutgoing == false || // incoming end
call.hasEnded   == true && call.isOutgoing == true {   // outgoing end
// Disconnected
}

if call.isOutgoing == true && call.hasConnected == false && call.hasEnded == false {
// "CXCallObserver : Dialing"

//**Write your logic written in for loop here**
}

if call.isOutgoing == false && call.hasConnected == false && call.hasEnded == false {
// "CXCallObserver: Incoming"
}

if call.hasConnected == true && call.hasEnded == false {
// "CXCallObserver: Connected")
}
}

注意:尽管这段代码是用swift语言编写的,但它很容易理解,也很容易转换为objective-c

//init
if (@available(iOS 10.0, *)) {
self.callObserver = [CXCallObserver new];
[self.callObserver setDelegate:self queue:nil];
}

并实现委托方法-CXCallObserverDelegate

#pragma mark - CXCallObserverDelegate
- (void)callObserver:(CXCallObserver *)callObserver callChanged:(CXCall *)call {
//what you need))
//call.isOutgoing
//call.hasConnected
//call.hasEnded
//call.onHold 
//call.hasEnded
}

相关内容

  • 没有找到相关文章

最新更新