Art*_*rti 3 google-authentication ios google-plus swift
我正在使用本教程在应用中使用谷歌登录.
pod 'GoogleSignIn', '~> 2.4.0'GSignIn-Bridging-Header.h带#import <GoogleSignIn/GoogleSignIn.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!) {
}
}
Run Code Online (Sandbox Code Playgroud)但是当我点击允许时
它将我重定向到google.com,而不是应用程序.
经过一天的工作,我终于解决了这个问题.@ayman Ibrahim基本上是对,但我认为答案有点宽泛.不同版本的Swift/Objective-C和Google SDK,在AppDelegate中调用不同版本的canOpenURL方法.我不是100%肯定这一点,并希望得到确认或纠正.这是适合我的那种方法的版本.我正在使用谷歌的SDK v.4.0,目标是iOS 9.1,并使用Swift 3.0:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let checkFB = FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
let checkGoogle = GIDSignIn.sharedInstance().handle(url as URL!,sourceApplication: sourceApplication,annotation: annotation)
return checkGoogle || checkFB
}
Run Code Online (Sandbox Code Playgroud)
我也在使用FBSDK,所以忽略那一行.
| 归档时间: |
|
| 查看次数: |
5572 次 |
| 最近记录: |