OutgoingCallController

OutgoingCallController

我正在尝试使用CallKit实现一个VoIP应用程序。一个特定的场景是接受来电和结束已在通话。一旦呼叫得到应答,我就会在OutgoingCallController中显示连接的呼叫接口。
所以在特定的场景中,我尝试关闭已经连接的OutgoingCallController,然后再次尝试使用新的传入呼叫详细信息呈现新的OutgoingCallController。
我试图呈现OutgoingCallController的逻辑是这些代码行。我在CXProviderDelegate类中调用此方法。

func displayOutgoingScreen() throws {

        SwiftyBeaver.verbose("Starting displayOutgoingScreen!! ")
        let storyBoard = UIStoryboard.init(name: DiallerProperties.storyBoard, bundle: nil)
        let incomingcallController:OutgoingCallWithAllController = storyBoard.instantiateViewController(withIdentifier: "outgoingWithAll") as! OutgoingCallWithAllController
        //incomingcallController.modalTransitionStyle = UIModalTransitionStyle.crossDissolve
        incomingcallController.number = AppDelegate().getIncomingCallNumber()
        SwiftyBeaver.verbose("Incoming call number is: \(incomingcallController.number)")
        DispatchQueue.main.async(execute: { () -> Void in

            let keyWindow =  UIApplication.shared.keyWindow
            var controller:UIViewController = (keyWindow?.rootViewController)!
            while  controller.presentedViewController != nil {
                controller=controller.presentedViewController!
            }
            let dateFormatter : DateFormatter = DateFormatter()
            dateFormatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
            let date = Date()
            let dateString = dateFormatter.string(from: date)
            let interval = date.timeIntervalSince1970
            print("presenting view here \(dateString) \(interval)!!")
            controller.present(incomingcallController, animated: true, completion: nil)
        });
    }

特定的日期代码用于日志记录,以查看这行代码的执行时间。
在OutgoingCallWithAllController viewwilldiscover方法中,我使用相同的日期逻辑来查看特定方法何时执行。
这是我收到的输出。
viewWillDisappear test 2019-03-01 13:34:32 1551427472.314188!!
presenting view here 2019-03-01 13:34:32 1551427472.324421!!

这是一条警告消息,我正在调试器日志的上面几行下面。
2019-03-01 13:34:32.344713+0530 [710:214818] Warning: Attempt to present <OutgoingCallWithAllController: 0x1040e9600> on <OutgoingCallWithAllController: 0x104042600> whose view is not in the window hierarchy!

这是一段代码,我用它来关闭我原来的OutgoingCallController。outgoingvc包含对OutgoingCallController的引用
AppDelegate.shared.outgoingvc?.dismiss(animated: false, completion: nil)

因为我试图解除旧的outgoingCallController并再次呈现它,所以我可以理解,我试图在已被解除的旧的outgoingCallController上呈现新的outgoingCallController。
所以我试着用下面的代码来延迟演示新控制器。
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
                //providing delay so that outgoing call controller has been closed
                action.fulfill()
                SwiftyBeaver.verbose("Executing after delay!!")

            }

但我还是无法控制。我怎样才能解决这个问题?
如果已经调查过这个问题:
Warning: Attempt to present * on * whose view is not in the window hierarchy - swift
Swift 3 Attempt to present whose view is not in the window hierarchy
我知道我要把那个旧的电话控制器作为顶视图。

最佳答案

我在间隔0.5秒后尝试获取最上面的视图控制器,即我在间隔0.5秒后调用displayOutgoingScreen函数,在这段时间内,我的旧传出控制器恰好被完全关闭,我可以看到我的传出屏幕。

10-08 07:29