In AppDelegate, the below function gets called whenever VoIP call (push notification) is received thereby creating multiple instances of "VideoCallViewController"
I've used deinit (in VideoCallViewController) as shown below, to check if the previous instance of "VideoCallViewController" was being de-initialised before a new instance of "VideoCallViewController" is created, to my surprise print("Deinitializing VC)
wasn't called, leaving the instance in memory.
How can I show VideoCallViewController with its Navigation Controller if an instance of VideoCallViewController already exists from AppDelegate.
In VideoCallViewController
deinit {
print("Deinitializing VC)
}
In AppDelegate
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
videoVC = storyboard.instantiateViewController(withIdentifier: "VideoCallViewController") as! VideoCallViewController
self.window = UIWindow(frame: UIScreen.main.bounds)
self.window?.rootViewController = videoVC
self.window?.makeKeyAndVisible()
}
Possible solution: Create singleton holding reference to nullable window, responsible for video calls flow. On notification change visible windows. On call end - return to the application main window.
E.G. :
And your method would look like:
You can create a lazy var in your AppDelegate
Then in your pushRegistry: