iZZiSwift

iZZiSwift

Learning by Sharing Swift Programing and more …

  • Swift Programming
    • Swift Language
    • i0S Swift Issue
  • Devices
  • MacOS
  • Python Programming
  • Kotlin Programming
  • Memo

Google Sign-in conflicts with Facebook login

December 4, 2020 Abreonia Ng
i0S Swift Issue

Question or problem in the Swift programming language:

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.

How to solve the problem:

Solution 1:

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)
       }
}

Solution 2:

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
  }

Solution 3:

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: [:])
    }
}

Solution 4:

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.

Solution 5:

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
    }

Solution 6:

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
        }
    }

Hope this helps!

Tagged avaudiosession cocoalumberjack-swift facebook-ios-sdk facebook-sdk-4.0 google-login google-maps-sdk-ios Integers in Swift iOS iOS Firmware ios-app-extension ios-autolayout ios-darkmode ios-extensions ios-frameworks objective-c-swift-bridge rx-swift Swift Swift 4 Swift 4.x swift-array swift-custom-framework swift-extensions xcode Xcode 10.2 xcode-command-line-tools xcode-instruments xcode-storyboard xcode-ui-testing xcode10 xcode10.1 xcode10.2 xcode11

Post navigation

Where is log file of mongodb in mac
Zip files corrupt over 4 gigabytes – No warnings or errors – Did I lose my data?

Related Posts

Could not complete submission of dSYM When fabric to firebase migration for crashlytics

December 4, 2020 Jeffrey Schneider
MacOS X Document shortcuts

Populate table view in swift

December 5, 2020 Aba Tayler

NSData from UInt8

December 20, 2020 Ollie MC

Same Catagory Posts

  • Get the length of a String in Swift
  • Convert Int to String in Swift
  • How to enumerate an enum with String type?
  • How to get overall CPU usage in iOS Swift 4.x
  • Get CPU usage percentage of single iOS App in Swift 4.x
  • Get the currently connected WiFi informations in Swift 4.x
  • Check internet connection with Swift 4.x
  • Check connection from iOS device to server by Swift 4.X
  • Get the server’s current time with Swift 4.X URLSession
  • Write a log text file on Disk use TextOutputStream in Swift 4 iOS
iZZiSwift | Developed by iZZi Team from 2017