ios - 允许后谷歌登录不重定向到应用程序

标签 ios swift google-plus google-authentication

我正在使用这个 tutorial在应用程序中使用 Google 登录。

  1. 我通过 cocoapods 安装了 GoogleSignIn。 pod 'GoogleSignIn', '~> 2.4.0'
  2. 已添加 GSignIn-Bridging-Header.h#import <GoogleSignIn/GoogleSignIn.h>里面。
  3. 创建 url 类型:enter image description here

  4. 使用 GIDSignInButton 创建 View 类

  5. 添加代码:

    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. 但是当我点击允许时

enter image description here

它将我重定向到 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/

相关文章:

ios - 使用 Google+ iOS API 如何获取登录用户的个人资料详细信息?

ios - 进入viewController后如何加载数据?

android - 使用 PhoneGap Build 的 BackgroundFetch/后台运行应用程序

ios - 如何在 iOS 中制作自定义对话框屏幕?

ios - iOS:13位置始终允许:点击“打开设置”后,它不会重定向到“应用程序设置”页面

android - Xamarin Android Google 登录 OnConnected 回调从未抛出

google-app-engine - "Google+ sign in"和 "Federated Log-in"和 "Google Users Service"有什么区别?

ios - CVPixelBuffer 导致设备上产生垃圾图像,而在模拟器上按预期工作

iOS 模拟器 CPU 负载

ios - 偷看时不调用prepareForSegue