我有一个服务类AuthManager,它具有如下方法:
public func logoutAuth(from viewController: UIViewController, completion:((_ result: Bool) -> Void)? = nil) {
let logoutString = "\(self.oAuthBaseServerURL)/logout.jsp"
// Present the Sign Off ViewController
if let logoutURL = URL(string: logoutString) {
let logoutController = SFSafariViewController(url: logoutURL)
let logoutDelegate = SFSafariViewDelegate(completion: completion)
logoutController.delegate = logoutDelegate
viewController.present(logoutController, animated: true, completion: nil)
}
}
我在视图控制器中从它的一个实例(处于全局状态的单个)调用该服务,如下所示:
GlobalState.AUTHMANAGER().logoutAuth(from: self, completion: self.completeLogout)
但是,我遇到此错误:
[Warning] Attempting to load the view of a view controller while it is deallocating is not allowed and may result in undefined behavior (<SFSafariViewController: 0x7ff9b1060800>)
我不确定为什么这样做分配得太早。我尝试将SFSafariViewController设置为实例变量,并改为在方法中分配它,这会产生相同的错误。