I am trying to implement a VoIP app using call Kit. A particular scenario is accepted incoming call and end already speaking call. Once call gets answered I show my connected call interface in OutgoingCallController.
So in the particular scenario, I am trying to dismiss the already connected OutgoingCallController and then trying to present new OutgoingCallController again with new Incoming call Details.
The logic I am trying to present OutgoingCallController is these lines of code. I am calling this method in CXProviderDelegate class.
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)
});
}
The particular date code is used for logging purposes to see the time this line of code is getting executed.
In OutgoingCallWithAllController viewWillDisappear method, I used the same date logic to see when that particular method is getting executed.
This is the output I'm receiving.
viewWillDisappear test 2019-03-01 13:34:32 1551427472.314188!!
presenting view here 2019-03-01 13:34:32 1551427472.324421!!
This is the warning message which I am getting below above lines in my debugger log.
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!
This is the piece of code I'm using to dismiss my old OutgoingCallController. outgoingvc contains reference to my OutgoingCallController
AppDelegate.shared.outgoingvc?.dismiss(animated: false, completion: nil)
Since I'm trying to dismiss the old outgoingCallController and present it again I can understand that I'm trying to present new outgoingCallController on the old one which has been already dismissed.
So I tried to delay the presenting new controller using below piece of code.
DispatchQueue.main.asyncAfter(deadline: .now() + 1.5) {
//providing delay so that outgoing call controller has been closed
action.fulfill()
SwiftyBeaver.verbose("Executing after delay!!")
}
But still, I don't have control. How can I fix this particular issue?
If in case already looked into this so questions:
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
I do understand I'm getting the old OutgoingCallController as a top view.