当前位置 : 主页 > 手机开发 > ios >

ios – Google允许后登录不会重定向到应用程序

来源:互联网 收集:自由互联 发布时间:2021-06-11
我正在使用此 tutorial在应用中使用谷歌登录. 我通过cocoapods安装了GoogleSignIn. pod’GoogleSignIn’,’〜 2.4.0′ 使用#import GoogleSignIn / GoogleSignIn.h添加了GSignIn-Bridging-Header.h内. 创建网址类型:
我正在使用此 tutorial在应用中使用谷歌登录.

>我通过cocoapods安装了GoogleSignIn. pod’GoogleSignIn’,’〜> 2.4.0′
>使用#import< GoogleSignIn / GoogleSignIn.h>添加了GSignIn-Bridging-Header.h内.
>创建网址类型:enter image description here
>使用GIDSignInButton类创建视图
>新增代码:

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!) {

}
}

>但是当我点击允许时

enter image description here

它将我重定向到google.com,而不是应用程序.

在AppDelegate中,您需要添加实现

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

Google通过URL发回信息,上述方法会捕获此信息并发送回应用程序.

网友评论