在允许后,Google登录不会重定向到应用程序 [英] Google sign in not redirect to application after allow

查看:140
本文介绍了在允许后,Google登录不会重定向到应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用


  • 使用创建视图GIDSignInButton class


  • 添加了代码:

      class ViewController:UIViewController,GIDSignInDelegate,GIDSignInUIDelegate {
    override func viewDidLoad(){
    super.viewDidLoad()
    GIDSignIn.sharedInstance()。delegate = self
    GIDSignIn.sharedInstance()。uiDelegate = self
    GIDSignIn.sharedInstance()。clientID =KEY
    }

    func signIn(登录:GIDSignIn!,didSignInForUser用户:GIDGoogleUser!,withError error:NSError!){
    if let err = error {
    print(错误)
    }
    else {
    print(GIDSignIn.sharedIn stance()。currentUser.profile.name)
    print(GIDSignIn.sharedInstance()。currentUser.profile.email)
    self.performSegueWithIdentifier(idSegueContent,sender:self)
    }
    }


    func signIn(signIn:GIDSignIn!,didDisconnectWithUser用户:GIDGoogleUser!,withError error:NSError!){

    }
    }


  • 但是当我点击允许




  • 它将我重定向到google.com,不要app。

    解决方案

    在AppDelegate中,你需要添加


    $ b的实现$ b

      func应用程序(应用程序:UIApplication,openURL url:NSURL,sourceApplication:String ?, annotation:AnyObject) - > Bool 
    {
    返回FBSDKApplicationDelegate.sharedInstance()。application(application,openURL:url,sourceApplication:sourceApplication,annotation:annotation)
    }

    Google通过网址发回信息,上述方法会捕获此信息并发回给应用程序。


    I'm using this tutorial to implement Sign in with google in app.

    1. I installed GoogleSignIn via cocoapods. pod 'GoogleSignIn', '~> 2.4.0'
    2. Added GSignIn-Bridging-Header.h with #import <GoogleSignIn/GoogleSignIn.h> inside.
    3. Create url types:

    4. Create a view with GIDSignInButton class

    5. Added code:

      class ViewController: UIViewController, GIDSignInDelegate,    GIDSignInUIDelegate {
      override func viewDidLoad() {
          super.viewDidLoad()
          GIDSignIn.sharedInstance().delegate = self
          GIDSignIn.sharedInstance().uiDelegate = self
          GIDSignIn.sharedInstance().clientID = "KEY" 
       }
      
       func signIn(signIn: GIDSignIn!, didSignInForUser user: GIDGoogleUser!, withError error: NSError!) {
      if let err = error {
         print(error)
      }
      else {
         print(GIDSignIn.sharedInstance().currentUser.profile.name)
         print(GIDSignIn.sharedInstance().currentUser.profile.email)
         self.performSegueWithIdentifier("idSegueContent", sender: self)
        }
      }
      
      
      func signIn(signIn: GIDSignIn!, didDisconnectWithUser user: GIDGoogleUser!, withError error: NSError!) {
      
      }
      }
      

    6. But when i click allow

    It redirects me to google.com, not to app.

    解决方案

    In the AppDelegate, You need to add the Implementation of

    func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool
    {
        return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
    }
    

    Google sends back information through URL, the method above captures this information and send back to the Application.

    这篇关于在允许后,Google登录不会重定向到应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆