I'm using this tutorial to implement Sign in with google in app.
pod 'GoogleSignIn', '~> 2.4.0'
GSignIn-Bridging-Header.h
with #import <GoogleSignIn/GoogleSignIn.h>
inside.Create url types:
Create a view with GIDSignInButton
class
Added code:
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!) {
}
}
But when i click allow
It redirects me to google.com, not to app.
I finally fixed this after a day's work. @ayman Ibrahim was basically, right, but I think that the answer is a bit broader. Different versions of Swift/Objective-C and the Google SDK, call different versions of the canOpenURL method in the AppDelegate. I'm not 100% certain about that, and would appreciate confirmation or correction. Here is the version of that method which worked for me. I am using Google's SDK v. 4.0, targeting iOS 9.1, and using 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
}
I am also using the FBSDK, so ignore that line.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With