1

私の AppDelegate は次のようになります。

class AppDelegate: UIResponder, UIApplicationDelegate,GIDSignInDelegate {
func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
    if let error = error {
        // ...
        return
    }

    guard let authentication = user.authentication else { return }
    let credential = GoogleAuthProvider.credential(withIDToken: authentication.idToken,
                                                   accessToken: authentication.accessToken)
}

//For ios 9.0 or above
func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any])
    -> Bool {

        return GIDSignIn.sharedInstance().handle(url,
                                                 sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
                                                 annotation: [:])
}

func application(_ application: UIApplication, open url: URL, sourceApplication:

    return GIDSignIn.sharedInstance().handle(url,
                                             sourceApplication: sourceApplication,
                                             annotation: annotation)
}

ストーリーボードに GIDSignIn ボタンを追加し、ViewController で UIDelegate を割り当てます。

class LoginRegisterViewController: UIViewController,UITextFieldDelegate,GIDSignInUIDelegate {
  override func viewDidLoad() {
    super.viewDidLoad()

    bindUIDelegate()
    GIDSignIn.sharedInstance().uiDelegate = self

            //registerForKeyboardNotifications()
}
.......

GIDSignInButton をクリックすると、Google Signin ページがポップアップ表示され、資格情報を入力してログインを押しました。次に、アプリに戻ります。

AppDeletgate.sign() メソッドにブレーク ポイントを挿入すると、アプリにリダイレクトされた後にヒットすることがわかります。しかし、ブレークポイントを配置しても、application:openurl メソッドが呼び出されることはありません。

だから私の質問は: そのメソッドはいつヒットしますか? ここからの認証プロセスの最後にあると言われています: https://firebase.google.com/docs/auth/ios/google-signin。しかし、私はそれがヒットしたことを見ていないし、 application:openurl メソッドを削除しても AppDeletgate.sign() はまだ正常に動作しているようです。

4

0 に答える 0