Search code examples
iosswift3facebook-loginbraintreegoogle-signin

Facebook Login + Google Login + Braintree Paypal Payment - AppDelegate issue


My app has google sign in, facebook sign in and braintree integration.

I have put the following code in appdelegate.swift:

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
}

func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
    if url.scheme?.localizedCaseInsensitiveCompare("com.release.braintreepayments") == .orderedSame {
        return BTAppSwitch.handleOpen(url, options: options)
    }
    return false
}

As I put the func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {}, my sign in's stop working, and if I comment this out,sign in works fine. Can you tell me how to combine both? I am sure there is some conflict in choosing one of both methods, but I need both.

I have contacted Braintree Support for the same too.


Solution

  • Try to use just second one:

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any]) -> Bool {
        if url.scheme?.localizedCaseInsensitiveCompare("com.release.braintreepayments") == .orderedSame {
            return BTAppSwitch.handleOpen(url, options: options)
        }
    
        guard let sourceApplication = options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String else {
                return false
            }
        let annotation =  options[UIApplicationOpenURLOptionsKey.annotation]
    
        let checkFB = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: sourceApplication, annotation: annotation)
        let checkGoogle = GIDSignIn.sharedInstance().handle(url as URL!,sourceApplication: sourceApplication,annotation: annotation)
    
        return checkFB || checkGoogle
    
    }