我正在使用这个 tutorial在应用程序中使用 Google 登录。
- 我通过 cocoapods 安装了 GoogleSignIn。
pod 'GoogleSignIn', '~> 2.4.0'
- 已添加
GSignIn-Bridging-Header.h
与#import <GoogleSignIn/GoogleSignIn.h>
里面。 使用
GIDSignInButton
创建 View 类添加代码:
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,而不是应用。
最佳答案
经过一天的工作,我终于解决了这个问题。 @ayman Ibrahim 基本上是对的,但我认为答案更广泛一些。不同版本的 Swift/Objective-C 和 Google SDK,在 AppDelegate 中调用不同版本的 canOpenURL 方法。我对此不是 100% 确定,希望得到确认或更正。这是对我有用的方法的版本。我正在使用 Google 的 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
}
我也在使用 FBSDK,所以请忽略该行。
关于ios - 允许后谷歌登录不重定向到应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35200852/