14

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.

Sunil Sharma
  • 2,653
  • 1
  • 25
  • 36
n0_quarter
  • 538
  • 1
  • 10
  • 23
  • When/where is that one line of code called? – Code Jun 13 '16 at 08:31
  • it's called on app start (didFinishLaunchingWithOptions) but after FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions) – n0_quarter Jun 13 '16 at 08:33
  • In didFinishLaunchingWithOptions function, return as follows:- `return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)` – pkc456 Jun 13 '16 at 09:00
  • Which method isn't invoked? The `application...openURL` method? So if you put a breakpoint there it doesn't work? – Code Jun 13 '16 at 10:24
  • Did you look at [this question](http://stackoverflow.com/questions/31506832/conflict-between-facebook-sign-in-and-google-sign-in-ios)? – Tomer Jun 13 '16 at 10:26
  • @tumber033 - yes, correct. The application...openURL method isn't invoked and I've found it out by putting a breakpoint there. Once I comment the line with GGLContext - then the application...openURL method is invoked. – n0_quarter Jun 13 '16 at 10:37
  • @Tomer: yes, I did look at your link and there's no solution. they suggest to do changes to the `application...openURL` method which is not invoked at all in my case – n0_quarter Jun 13 '16 at 10:41
  • @n0_quarter try this http://stackoverflow.com/questions/36847848/facebook-and-google-login-conflict-xcode/36855497#36855497 – Bhavin Bhadani Jun 13 '16 at 11:24

6 Answers6

8

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)
       }
}
Sunil Sharma
  • 2,653
  • 1
  • 25
  • 36
  • Please read edits to my question. the thing is, that the `application...openURL` method isn't invoked at all in my case. Once I comment the line with GGLContext - then the `application...openURL` method is invoked. – n0_quarter Jun 13 '16 at 10:43
  • just try to return even for google as show in my answer.Currently u r only returning for facebook. – Sunil Sharma Jun 13 '16 at 10:54
  • Ok, I've tried your solution and it didn't work. Facebook login prompt remains. Anyways, I don't understand how this possibly could work if the method `application...openURL ` isn't invoked at all – n0_quarter Jun 13 '16 at 11:55
5

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
  }
n0_quarter
  • 538
  • 1
  • 10
  • 23
  • 1
    thats what i done it in this answer which i commented http://stackoverflow.com/questions/36847848/facebook-and-google-login-conflict-xcode/36855497#36855497 :) – Bhavin Bhadani Jun 15 '16 at 08:08
1

I just implemented this code using the latest versions of Facebook and Google pods and Swift 3.1 and it worked great!

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

    if url.absoluteString.contains("facebook") {
        return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: [:])
    } else {
        return GIDSignIn.sharedInstance().handle(url,
                                                 sourceApplication:options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                 annotation: [:])
    }
}
Chase McElroy
  • 383
  • 3
  • 8
  • People keep suggesting this. It may be working code, but has nothing to do with my question. if you read my question, you'd notice that in my case the method application: open url: options: is not invoked at all. – n0_quarter Apr 28 '17 at 09:48
  • You are using "openURL url: NSURL" in your code, and I'm providing a solution to people who stumble upon your question and are using Xcode 8 and Swift 3.1. I am not suggesting you implement my code with Xcode Version 7.3.1. – Chase McElroy Jun 06 '17 at 23:58
0

If you are using google documentation for the integration of their auth system, don't use this method :

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
    var returnVal = false
    if #available(iOS 9.0, *) {
        returnVal = GIDSignIn.sharedInstance().handle(url,sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,annotation: options[UIApplicationOpenURLOptionsKey.annotation])
    } else {
        returnVal = false
    }
    return returnVal
}

This is supposed to work for avoid conflicts with iOS 9, but as soon as i removed this, the fb log in worked and the google log in worked on an iOS 9 device too.

Hope this help anybody.

0

In Swift 3 (iOs 10) just do like this: (it worked fine for me)

        func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

// FACEBOOK            
let handled = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)

// GOOGLE
GIDSignIn.sharedInstance().handle(url,
                                                     sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                     annotation: options[UIApplicationOpenURLOptionsKey.annotation])
        return handled
    }
Ivan Sinigaglia
  • 1,052
  • 7
  • 16
  • People keep suggesting this. It may be working code, but has nothing to do with my question. if you read my question, you'd notice that in my case the method application: open url: options: is not invoked at all. – n0_quarter Apr 28 '17 at 09:47
0

This worked on Swift 3: I had Facebook and Google Login in the same page.

 @available(iOS 9.0, *)
    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
        print( " open URL : \(url.absoluteURL.absoluteString)")

        if url.absoluteURL.absoluteString.contains("fb728991920603705") //Facebook ID from Plist
        {
            print("contain FB ID")
            return FBSDKApplicationDelegate.sharedInstance().application(app, open: url, options: options)

        }
        else {
            let result = GIDSignIn.sharedInstance().handle(url,
                                                           //added exclamation mark
                sourceApplication: String(describing: options[UIApplicationOpenURLOptionsKey.sourceApplication]!),
                annotation: options[UIApplicationOpenURLOptionsKey.annotation])
            return result
        }
    }
Alvin George
  • 14,148
  • 92
  • 64
  • People keep suggesting this. It may be working code, but has nothing to do with my question. if you read my question, you'd notice that in my case the method application: open url: options: is not invoked at all. – n0_quarter Apr 28 '17 at 09:48