Facebook and Google+ Sign-In

2019-06-23 22:35发布

I'm using both Google+ and Facebook in my app. My problem is that both of them require the OpenURL method in the appDelegate.

For Facebook login:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}    

For Google+ login:

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool {
    return GPPURLHandler.handleURL(url, sourceApplication: sourceApplication, annotation: annotation)
}

How can I use both google+ and facebook in the same app?

2条回答
Animai°情兽
2楼-- · 2019-06-23 23:06

Solution Updated for Xcode 7.0 and Swift 2.0

return FBSDKApplicationDelegate.sharedInstance().application(app, openURL: url, sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String, annotation: nil)  ||
            GPPURLHandler.handleURL(url, sourceApplication: options["UIApplicationOpenURLOptionsSourceApplicationKey"] as! String, annotation: nil)

**

Swift 3.0 another solution

**

 func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
        if url.scheme == "fb1675189366130133" {
        return FBSDKApplicationDelegate.sharedInstance().application(application,
                                                         open: url,
                                                         sourceApplication: sourceApplication,
                                                         annotation: annotation)
        }else{
            return GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation)
        }
}
查看更多
时光不老,我们不散
3楼-- · 2019-06-23 23:06

I found a solution, use this bit of code:

if url.scheme == "fb1111111111111" {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
} else {
    return GPPURLHandler.handleURL(url, sourceApplication: sourceApplication, annotation: annotation)
}    
查看更多
登录 后发表回答