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 登录页面,然后我输入我的凭据并点击登录。然后它引导我回到我的应用程序。

我在 AppDeletgate.sign() 方法中插入了一个断点,我可以看到它在重定向回应用程序后确实被击中。但是我没有看到我的 application:openurl 方法被调用,即使我在其中设置了一个断点。

所以我的问题是:这种方法什么时候受到影响?据说在身份验证过程结束时从这里开始:https ://firebase.google.com/docs/auth/ios/google-signin 。但我没有看到它被击中,即使我删除了 application:openurl 方法,AppDeletgate.sign() 似乎仍然可以正常工作。

4

0 回答 0