<legend id='6o2fh'><style id='6o2fh'><dir id='6o2fh'><q id='6o2fh'></q></dir></style></legend>

      <small id='6o2fh'></small><noframes id='6o2fh'>

      <i id='6o2fh'><tr id='6o2fh'><dt id='6o2fh'><q id='6o2fh'><span id='6o2fh'><b id='6o2fh'><form id='6o2fh'><ins id='6o2fh'></ins><ul id='6o2fh'></ul><sub id='6o2fh'></sub></form><legend id='6o2fh'></legend><bdo id='6o2fh'><pre id='6o2fh'><center id='6o2fh'></center></pre></bdo></b><th id='6o2fh'></th></span></q></dt></tr></i><div id='6o2fh'><tfoot id='6o2fh'></tfoot><dl id='6o2fh'><fieldset id='6o2fh'></fieldset></dl></div>
      1. <tfoot id='6o2fh'></tfoot>
          <bdo id='6o2fh'></bdo><ul id='6o2fh'></ul>

        避免创建多个 ViewController 实例,iOS Swift

        时间:2023-06-12

            <tbody id='FC1XM'></tbody>
              • <tfoot id='FC1XM'></tfoot><legend id='FC1XM'><style id='FC1XM'><dir id='FC1XM'><q id='FC1XM'></q></dir></style></legend>

                • <bdo id='FC1XM'></bdo><ul id='FC1XM'></ul>
                  <i id='FC1XM'><tr id='FC1XM'><dt id='FC1XM'><q id='FC1XM'><span id='FC1XM'><b id='FC1XM'><form id='FC1XM'><ins id='FC1XM'></ins><ul id='FC1XM'></ul><sub id='FC1XM'></sub></form><legend id='FC1XM'></legend><bdo id='FC1XM'><pre id='FC1XM'><center id='FC1XM'></center></pre></bdo></b><th id='FC1XM'></th></span></q></dt></tr></i><div id='FC1XM'><tfoot id='FC1XM'></tfoot><dl id='FC1XM'><fieldset id='FC1XM'></fieldset></dl></div>

                  <small id='FC1XM'></small><noframes id='FC1XM'>

                  本文介绍了避免创建多个 ViewController 实例,iOS Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  在 AppDelegate 中,每当收到 VoIP 呼叫(推送通知)时,都会调用以下函数,从而创建多个VideoCallViewController"实例

                  In AppDelegate, the below function gets called whenever VoIP call (push notification) is received thereby creating multiple instances of "VideoCallViewController"

                  如下所示,我使用 deinit(在 VideoCallViewController 中)来检查是否在创建新的VideoCallViewController"实例之前取消了先前的VideoCallViewController"实例,令我惊讶的是 print("Deinitializing VC) 未被调用,将实例留在内存中.

                  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.

                  如果 AppDelegate 中已经存在 VideoCallViewController 的实例,我如何显示 VideoCallViewController 及其导航控制器.

                  How can I show VideoCallViewController with its Navigation Controller if an instance of VideoCallViewController already exists from AppDelegate.

                  在 VideoCallViewController 中

                  deinit {
                    print("Deinitializing VC)
                  }
                  

                  在 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.

                  例如:

                  class VideoCallManager {
                      //MARK: - Singleton
                      static let sharedInstance = VideoCallManager()
                      private init() {}
                  
                      private var videoCallWindow: UIWindow?
                  
                      func navigateToVideoCallViewController() {
                          if let window = self.videoCallWindow, window.keyWindow {
                               //VideoCallViewController is displayed at the moment.
                               return
                          }
                  
                          videoCallWindow = UIWindow.init(frame: UIScreen.mainScreen().bounds)
                          let storyboard = UIStoryboard(name: "Main", bundle: nil)
                          videoVC = storyboard.instantiateViewController(withIdentifier: "VideoCallViewController") as! VideoCallViewController
                  
                          self.videoCallWindow?.rootViewController = videoVC
                          self.videoCallWindow?.makeKeyAndVisible()
                      }
                  
                      func returnToWindowOfAppDelegate() {
                          if let window = self.videoCallWindow, window.keyWindow {
                              (UIApplication.sharedApplication().delegate as? AppDelegate)?.window?.makeKeyAndVisible()
                  
                              self.videoCallWindow = nil
                          }
                      }
                  }
                  

                  你的方法看起来像:

                  func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
                      VideoCallManager.sharedInstance.navigateToVideoCallViewController()
                  }
                  

                  这篇关于避免创建多个 ViewController 实例,iOS Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:iOS7:如何在 iOS7 上添加固定的搜索栏,如联系人? 下一篇:将 MFMailComposeViewController 推送到导航堆栈上?未以模态方式呈现

                  相关文章

                    <bdo id='4ICaP'></bdo><ul id='4ICaP'></ul>
                  1. <tfoot id='4ICaP'></tfoot>
                  2. <i id='4ICaP'><tr id='4ICaP'><dt id='4ICaP'><q id='4ICaP'><span id='4ICaP'><b id='4ICaP'><form id='4ICaP'><ins id='4ICaP'></ins><ul id='4ICaP'></ul><sub id='4ICaP'></sub></form><legend id='4ICaP'></legend><bdo id='4ICaP'><pre id='4ICaP'><center id='4ICaP'></center></pre></bdo></b><th id='4ICaP'></th></span></q></dt></tr></i><div id='4ICaP'><tfoot id='4ICaP'></tfoot><dl id='4ICaP'><fieldset id='4ICaP'></fieldset></dl></div>

                  3. <small id='4ICaP'></small><noframes id='4ICaP'>

                    1. <legend id='4ICaP'><style id='4ICaP'><dir id='4ICaP'><q id='4ICaP'></q></dir></style></legend>