我正在使用此 tutorial在应用中使用谷歌登录. 我通过cocoapods安装了GoogleSignIn. pod’GoogleSignIn’,’〜 2.4.0′ 使用#import GoogleSignIn / GoogleSignIn.h添加了GSignIn-Bridging-Header.h内. 创建网址类型:
>我通过cocoapods安装了GoogleSignIn. pod’GoogleSignIn’,’〜> 2.4.0′
>使用#import< GoogleSignIn / GoogleSignIn.h>添加了GSignIn-Bridging-Header.h内.
>创建网址类型:
>使用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!) { } }
>但是当我点击允许时
它将我重定向到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发回信息,上述方法会捕获此信息并发送回应用程序.