簡體   English   中英

電容器自定義插件 swift - 從 AppDelegate 訪問 viewController 和原始 window

[英]Capacitor custom plugin swift - access viewController and original window from AppDelegate

我正在創建一個電容器插件,但我在將一些參數傳遞給第三方框架時遇到了問題。

該方法應接收:

  • restoreViewController: 原始視圖控制器
  • window:來自 AppDelegate 的原始 window

然后我應該更新 AppDelegate window。我有一個實現的代碼示例:

guard let appDelegate = UIApplication.shared.delegate as? AppDelegate else { return }

var window: UIWindow?

method(
  restoreViewController: appDelegate.window.rootViewController,
  window: &window
)

 appDelegate?.window = window

但這不起作用。 appDelegate 是 <App.AppDelegate> 並返回。 所以,我試過

 guard let window = UIApplication.shared.delegate?.window
 window?.rootViewController

 self.bridge?.viewController

但它會引發錯誤

Unbalanced calls to begin/end appearance transitions for <...>.

實在不知道傳什么和更新什么,我對swift不是很熟練。

有人可以幫助我嗎?

嘗試這個

DispatchQueue.main.async {
    let window = self.bridge?.viewController?.view.window
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM