#class GPPSignInButton;
I don't want use the GPPSignInButton for login and authentication i want to use my custom button when i pressed then the login process will start and the login with the Forcefully webview like facebook did it is possible in Google+ login too?
like the "Using the OAuth 2 Controllers"
Thanks in advance
anyhelp will be appreciated.
Yes you can use any UIButton instead of using GPPSignInButton.
Initialise the Google+ sdk in viewDidLoad using :
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to not get the user's email
signIn.clientID = kClientId;
signIn.scopes = [NSArray arrayWithObjects:kGTLAuthScopePlusMe,kGTLAuthScopePlusLogin, nil];
signIn.delegate = self;
Now in the uibutton action
- (IBAction)googlePlusSignIn:(id)sender
{
GPPSignIn *signIn = [GPPSignIn sharedInstance];
if([[GPPSignIn sharedInstance] authentication])
{
[signIn trySilentAuthentication];
}
else
{
// This is method that opens the G+ sign view
[signIn authenticate];
}
}
Add URL type and URL scheme in Targets -> Info -> URL Types .
Then add the following in App Delegate
- (BOOL)application: (UIApplication *)application
openURL: (NSURL *)url
sourceApplication: (NSString *)sourceApplication
annotation: (id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
Related
Is there a way to provide user email to GPPSignIn object before calling [self.signIn authenticate]; so user wouldn't have to enter it in browser/Google Plus app to login in using Google account? I want to pass user email to the login form so the user had only to enter the password. I ask user for email earlier, so in most scenarios I can use it to help him login in fewer steps. self.signIn.userEmail is read-only so won't help me much.
user need to enter email and password if its the first time else doesn't have to.
- (IBAction)Btn_gogleShare:(id)sender {
if ([[GPPSignIn sharedInstance] authentication]) {
NSLog(#"share");
[self GoogleShare];
} else {
NSLog(#"Login");
[self GoogleLogin];
}
}
#pragma mark - Google+ ALL ACTIVITY
#pragma mark - Google+ Login
- (void)GoogleLogin{
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES; // Uncomment to get the user's email
// You previously set kClientId in the "Initialize the Google+ client" step
signIn.clientID = kClientID;
signIn.scopes = #[ kGTLAuthScopePlusLogin ];
//signIn.scopes = #[ #"profile" ]; // "profile" scope
// Optional: declare signIn.actions, see "app activities"
signIn.delegate = self;
[signIn authenticate];
[self showLoadingView:#"Authorizing..."];
}
- (void)finishedWithAuth: (GTMOAuth2Authentication *)auth
error: (NSError *) error {
NSLog(#"Received error %# and auth object %#",error, auth);
// NSLog(#"%#", signIn.authentication.userEmail);
[self hideLoadingView];
[self GoogleShare];
}
#pragma mark - Google+ share
- (void)GoogleShare{
id<GPPNativeShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];
// This line will fill out the title, description, and thumbnail from
// the URL that you are sharing and includes a link to that URL.
[shareBuilder setURLToShare:[NSURL URLWithString:#"https://www.example.com/restaurant/sf/1234567/"]];
[shareBuilder open];
}
#pragma mark - Google+ signOut
- (void)signOut {
[[GPPSignIn sharedInstance] signOut];
}
when i signin in the Main ViewController in my Case ViewController.m every think works fine
with same code i sign in on other UIViewController login.m
when i close the app and run again trysilentauthentication will return false always
its lookalike nothing saved
i use this code to sign in login.m :
signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.clientID = kClientId;
signIn.scopes = #[ kGTLAuthScopePlusLogin ];
signIn.delegate = self;
[signIn authenticate];
and i check in ViewController.m :
if ([signIn trySilentAuthentication]) {
NSLog(#"trySilentAuthentication Return True");
}else {
NSLog(#"trySilentAuthentication Return False");
}
and i sign out in login.m using :
- (IBAction)signOut:(id)sender {
[self ClearUserData];
[[GPPSignIn sharedInstance] signOut];
[self refreshInterfaceBasedOnSignIn];
}
is it something With Delegate ?
I am trying to set up Google login on my app and I have setup the following function for it:
-(void) performGoogleLogin{
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.clientID = kClientId;
signIn.scopes = #[ #"email" ];
signIn.delegate = self;
[signIn authenticate];
}
When I do this the first time, the app opens Safari where I grant permissions. After returning to my app, this function in my AppDelegate gets called:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
But then, the -(void) finishedWithAuth:(GTMOAuth2Authentication *)auth error:(NSError *)error function does not get called immediately. It only gets called when I invoke the performGoogleLogin function by clicking my button a second time. Any idea why this might be happening?
Looks like a duplicate of finishedWithAuth not called after authenticate method
Make GPPSignIn a class-level variable to avoid it getting garbage collected when the device switches to Safari for the login.
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 ?
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 ).
I have implemented Google Plus Api and login as it is given in the site. But it is giving problem after login when I click on allow Access as shown below:
The following message appears :
My Code is as follows,pls tell me If anything left:
- (void)viewDidLoad
{
self.signInButton.delegate = self;
self.signInButton.clientID = kClientId;
self.signInButton.scope = [NSArray arrayWithObjects:
#"https://www.googleapis.com/auth/plus.me",
nil];
SLNetworkAppDelegate *appDelegate = (SLNetworkAppDelegate*)
[[UIApplication sharedApplication] delegate];
appDelegate.signInButton = self.signInButton;
share =[[GPPShare alloc] initWithClientID:kClientId];
share.delegate = self; // optional
appDelegate.share=share;
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (IBAction) didTapShare: (id)sender {
[[[[share shareDialog]
setURLToShare:[NSURL URLWithString:#"https://developers.google.com/+/mobile/ios/getting-started"]]
setPrefillText:#"testing share via google plus"] open];
// Or, without a URL or prefill text:
[[share shareDialog] open];
}
In App delegate file:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if ([signInButton handleURL:url
sourceApplication:sourceApplication
annotation:annotation]) {
return YES;
}
if ([self.share handleURL:url
sourceApplication:sourceApplication
annotation:annotation]) {
return YES;
}
return NO;
}
You have to assign redirect uri in your project with your bundle ID like this so after successful authentication your application will be launched from safari if your handle your url properly:
Place bundle Id as identifier and URLSchemes...