Facebook and Google+ Sign-In

限于喜欢 提交于 2019-12-10 17:34:42

问题


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?


回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/31221476/facebook-and-google-sign-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!