2

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

Community
  • 1
  • 1
Stefano
  • 33
  • 1
  • 7

4 Answers4

5

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;
}
Waruna
  • 162
  • 8
  • I will try this out and let you know. Thanks. – Stefano Jul 26 '15 at 20:03
  • When I use FBAppCall with the latest iOS SDK 4.5.1, I get the "use of undeclared identifier" message. Which iOS SDK version are you using? – SAHM Aug 16 '15 at 02:41
  • @Waruna I checked your answer but, provided I can get the Access Token to insert in the suggested condition, I receive an error for the FBSession (unkown receiver) and another one for FBAppCall (use of undeclared identifier), similar to what described by the other user above. I'm using the iOS SDK 4.4. Any ideas on how to solve this? – Stefano Aug 23 '15 at 19:18
  • To work around the issues I mentioned above, I have written the following. However, the code seems to be by-passed during the execution. I will keep working on this: – Stefano Aug 23 '15 at 22:52
  • - (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation { if ([GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]) { //Google Plus method return YES; } else { //Facebook method return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; } } – Stefano Aug 23 '15 at 22:52
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)

}
0

Check whether you implement or not GPPURLHandler method inside

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

}
    -
Waruna
  • 162
  • 8
  • thanks for your answer. This is exactly the point. Facebook requires a similar Handler in the same way that GooglePlus needed it (hence my shift to Google Sign In). Now you point out to use the same handler for Google Sign In. This is what I have in the method: – – Stefano Jul 25 '15 at 01:58
  • //GooglePlus ATTEMPT return [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]; //Facebook return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; – Stefano Jul 25 '15 at 01:58
  • I am confused on how the two can work together since so far, as soon as I uncomment the Google block, I got a nice conflict from the Facebook block. Thanks again. – Stefano Jul 25 '15 at 01:59
  • I was finally able to implement your solution. Also, with the help of this video: https://www.youtube.com/watch?v=1fItuKMrnpE – Stefano Nov 11 '15 at 01:04
  • Now the big issue that will probably not be solved given the lack of support offered by Parse is to link the Google+ Sign In authentication to Parse itself (bring your sign in example via Git Hub has no details). But that's another story. Thanks once again @Waruna – Stefano Nov 11 '15 at 01:06
-1

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

Ralph
  • 716
  • 5
  • 9