Conflict between Facebook Sign In and Google Sign In - iOS

半世苍凉 提交于 2019-12-11 03:02:29

问题


I've successfully deployed a Log In via Facebook in my app. I've then tried to add the possibility to log in via Google+ but I gave up after a few long nights of coding and a few posts from people much more advanced than I am concluding on the roadblocks existing at the moment example: How can I login to google-plus using google-plus-ios-sdk-1.7.1 sdk?.

I am now trying to implement a Google Sign In by following the seemingly easy instructions from the Google Developer site.

However the way this is explained by Google creates several conflicts with the set-up needed for running the Log In via Facebook. I have tried to rewrite the Facebook code by using a Pod and installing it at the same time I install the Google Sign In but I was not able to make it work (still something hindering the authentication via Facebook).


回答1:


Implement like this way.

- (BOOL)  application:(UIApplication *)application
              openURL:(NSURL *)url
    sourceApplication:(NSString *)sourceApplication
           annotation:(id)annotation {


    if ([[url scheme] isEqualToString:FBTOKEN]) {
        return [FBSession.activeSession handleOpenURL:url];

        return [FBAppCall handleOpenURL:url
                      sourceApplication:sourceApplication
                            withSession:FBSession.activeSession];
    }
    else { 
            [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];

    }
  return YES;
}



回答2:


I implemented this way for Google and Facebook

func application(application: UIApplication,
    openURL url: NSURL,
    sourceApplication: String?,
    annotation: AnyObject) -> Bool {

        let options: [String: AnyObject] = [UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication!,
            UIApplicationOpenURLOptionsAnnotationKey: annotation]

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

}



回答3:


Check whether you implement or not GPPURLHandler method inside

-(BOOL) application:(UIApplication *)application
              openURL:(NSURL *)url
    sourceApplication:(NSString *)sourceApplication
           annotation:(id)annotation { 

}
    -



回答4:


This worked for me with Google Sign In version 2.4.0 and Facebook ios SDK 4.10.0

1) Remove the method

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

from AppDelegate

2) Implement as following :

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {



        if url.scheme == "fbxxxxxxxxxxxx" {
            return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
        }
        else {
            let options: [String: AnyObject] = [UIApplicationOpenURLOptionsSourceApplicationKey: sourceApplication!,
                UIApplicationOpenURLOptionsAnnotationKey: annotation]

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


    }

The fb url scheme is taken from Url Schemes in Info.plist



来源:https://stackoverflow.com/questions/31506832/conflict-between-facebook-sign-in-and-google-sign-in-ios

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