Google登录iPad中的用户代理问题

时间:2017-01-11 09:23:48

标签: ios swift ipad google-signin

我在我的应用中使用谷歌登录。我已经通过firebase配置了链接https://firebase.google.com/docs/auth/ios/google-signin中给出的步骤。我的问题是,当我在iPhone中打开我的应用程序时,它会重定向到移动浏览器并且工作得很好。但是当我在iPad上打开应用程序时,它会在Webview中打开,因此会出现用户代理问题。

enter image description here

有人可以建议我如何强制该应用程序进入浏览器,即使它在iPad中打开。

我附上了我的代码以供参考

 @available(iOS 9.0, *)
func application(_ application: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any])
    -> Bool
{
    return GIDSignIn.sharedInstance().handle(url,
                                             sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                             annotation: [:])
}

func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool
{
    return GIDSignIn.sharedInstance().handle(url,
                                             sourceApplication: sourceApplication,
                                             annotation: annotation)
}

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error?)
{
    if error != nil {
        // ...
        print(error!)

        return
    }

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

    FIRAuth.auth()?.signIn(with: credential) { (user, error) in

        print(user!)

        GIDSignIn.sharedInstance().signOut()

        self.view.hideToastActivity()
        self.getUserDetails(email: (user?.email)!)

        if error != nil {
            // ...
            print(error!)

            return
        }
    }
}
func sign(_ signIn: GIDSignIn!, didDisconnectWith user:GIDGoogleUser!,
          withError error: Error!) {
    // Perform any operations when the user disconnects from app here.
    // ...

    if error != nil {
        // ...
        print(error)
        return
    }
}

1 个答案:

答案 0 :(得分:0)

如果您使用的是GTM-OAuth2库,谷歌已经提到它已经弃用了GTM-OAuth2库依赖的Web视图。他们建议使用GTMAppAuth库。