Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Sign-in conflicts with Facebook login

I'm using Google Sign-in and Facebook Login to provide Google and Facebook login in my app.

The problem is, when I'm using them both - Facebook Login Screen (based on Safari View Controller) doesn't dismiss after user logged in.

After hours of painful debugging I found out that the problem only appears if I initialise Google Sign-in before showing Facebook login prompt.

Basically, it's one line.

GGLContext.sharedInstance().configureWithError(&configureError)

If I comment that line - Facebook login works fine.

EDIT: This is what I have in my AppDelegate.swift:

 func application(application: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(application,
                                                                openURL: url,
                                                                sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String,
                                                                annotation: options [UIApplicationOpenURLOptionsAnnotationKey])

And the sad thing is that this method isn't invoked at all. But if I disable Google Login - it works fine.

Additional details: I'm using Facebook SDK v4.12.0 and Google Sign-In SDK v4.0.0

Xcode Version 7.3.1 (7D1014), tested on iOS 9.3

Any ideas are welcome.

like image 294
n0_quarter Avatar asked Jun 10 '16 15:06

n0_quarter


2 Answers

I am also using both google and facebook login and it is working fine.You have to use below method func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject) -> Bool as

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String, annotation: AnyObject) -> Bool {

       if url.absoluteString().containsString("FACEBOOK_ID") {
             return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
       }
       else {
           return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: sourceApplication, annotation: annotation)
       }
}
like image 176
Sunil Sharma Avatar answered Sep 24 '22 18:09

Sunil Sharma


Ok folks, eventually I've figured it out. The trick which worked for me is to initialise Google Sign-In SDK before the Facebook SDK.

now my AppDelegate looks like this:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

    // Initialize google sign-in
    var configureError: NSError?
    GGLContext.sharedInstance().configureWithError(&configureError)
    assert(configureError == nil, "Error configuring Google services: \(configureError)")

    // init FB SDK
    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)

  return true
  }
like image 33
n0_quarter Avatar answered Sep 22 '22 18:09

n0_quarter