iOS Facebook and Google login at the same time?

人盡茶涼 提交于 2019-12-29 07:14:33

问题


I'm trying to implement google+ and facebook sign ins in the same app. I followed the instructions by Parse and Google and I first successfully implemented Facebook login. Then I started to follow the google instructions. After doing that, now I'm having these 2 functions in my AppDelegate.swift file:

For google:

func application(application: UIApplication,
    openURL url: NSURL, options options: [String: AnyObject]) -> Bool {
        return GIDSignIn.sharedInstance().handleURL(url,
            sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey],
            annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}

For facebook:

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

Do I need to combine these 2 blocks of code into 1 as seen in some posts such as

Google SignIn SFSafariViewController/WebView redirects to Google.com after accepting permissions

or they can stay like that in 2 different blocks? Thanks


回答1:


You need to combine them. The simplest way is to use an || on the return statement. Try this:

func application(application: UIApplication,
    openURL url: NSURL, options: [String: AnyObject]) -> Bool {

        return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String, annotation: nil)  ||
            GIDSignIn.sharedInstance().handleURL(url,
            sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String,
            annotation: options[UIApplicationOpenURLOptionsAnnotationKey] as? String)
}



回答2:


You would be well served to use Google Identity Toolkit (now repackaged as Firebase) to achieve this and allow extensions to other IDP's as well



来源:https://stackoverflow.com/questions/34125280/ios-facebook-and-google-login-at-the-same-time

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