![](/img/trans.png)
[英]Swift - Accessing AppDelegate window from viewController
[英]Capacitor custom plugin swift - access viewController and original window from AppDelegate
我正在創建一個電容器插件,但我在將一些參數傳遞給第三方框架時遇到了問題。
該方法應接收:
然后我應該更新 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.