5

How to customize Google+ Sign-In button ios ?

is there a way to go directly for sign in with out clicking Google+ Sign-In button ?

Rijesh Pv
  • 139
  • 1
  • 9

1 Answers1

12

Yes, there is way to directly sign in Google+.

In AppDelegate, add this,

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
       return [GPPURLHandler handleURL:url
                      sourceApplication:sourceApplication
                             annotation:annotation];   
}

And your login view controller this code parts should be added.

- (void)loginWithGooglePlus
{
    [GPPSignIn sharedInstance].clientID = kClientID;
    [GPPSignIn sharedInstance].scopes= [NSArray arrayWithObjects:kGTLAuthScopePlusLogin, nil];
    [GPPSignIn sharedInstance].shouldFetchGoogleUserID=YES;
    [GPPSignIn sharedInstance].shouldFetchGoogleUserEmail=YES;
    [GPPSignIn sharedInstance].delegate=self;

    [[GPPSignIn sharedInstance] authenticate];
}

- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
                   error:(NSError *)error
{
    if (!error)
    {
        NSLog(@"Google+ login successful");
    }
    else
    {
        NSLog(@"Error: %@", error);
    }
}

kClientID is your app client id taken from google your registered apps. Of course you need to set the delegate ( GPPSignInDelegate ).

caglar
  • 1,079
  • 1
  • 9
  • 17
  • Thanks for the reply. How do we get friends list(their emails) after successful login ? – Rijesh Pv Dec 05 '13 at 11:39
  • *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryM gtm_httpArgumentsString]: unrecognized selector sent to instance 0xb65ee70' error occuring – Muruganandham K Mar 17 '14 at 10:05
  • @iTroyd23 - I know it been a long time but FYI - to avoid that crash you need to add `-Objc` in `Other Linker Flags` [Described here](http://www.riskcompletefailure.com/2013/06/common-issues-with-google-sign-in-on-ios.html) – Rahul Mane Jun 29 '15 at 06:43