私は自分のアプリケーションでFirebaseを使用しています.Google Signin関数を追加したいと思います。 Googleによると、サイン機能を私のAppdelegateに追加する必要があります。私の問題は、私がappdelegateからログインを実行したいのであれば、どのようにしてユーザーにエラーを表示できるかということです。私は次のコードを試しました。App Delegateからエラーを表示する - Google Signin
public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!){
if let error = error {
print()
let importantAlert: UIAlertController = UIAlertController(title: "Error", message: "\(error.localizedDescription)", preferredStyle: .alert)
self.window?.rootViewController?.present(importantAlert, animated: true, completion: nil)
return
}
let authentication = user.authentication
let credential = FIRGoogleAuthProvider.credential(withIDToken: (authentication?.idToken)!,
accessToken: (authentication?.accessToken)!)
FIRAuth.auth()?.signIn(with: credential, completion: { [weak self](user, error1) in
if(error != nil){
let importantAlert: UIAlertController = UIAlertController(title: "Error", message: "\(error1!.localizedDescription)", preferredStyle: .alert)
self?.window?.rootViewController?.present(importantAlert, animated: true, completion: nil)
}
})
}
そして私は
Warning: Attempt to present <UIAlertController: 0x7f864b62bef0> on <SFSafariViewController: 0x7f864b40edb0> whose view is not in the window hierarchy!
私は何をすべき次のエラーを取得しますか?
をあなたの 'self.window .rootViewController.view'はあなたのビューではではないように思われます。 self.window?.rootViewControllerを設定してコードを投稿してください。 – shallowThought
サインインメソッドを呼び出すView Controllerがあります。私は実際にはrootViewControllerを設定していません。 –
ナビゲーションコントローラを使用していますか?また、ストーリーボード階層でQを更新してください。 – Dravidian