Google Plus Sign in From other UIViewController - ios

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 ?

Related

how to get UserID from Google plus Oauth2.0 for IOS

I used Google Developers Documentation but I can't take UserID
this is my code:
- (void)viewDidLoad
{
[super viewDidLoad];
self.navigationController.navigationBar.barTintColor = [UIColor colorWithRed:0.0f/255.0f green:102.0f/255.0f blue:204.0f/255.0f alpha:100.0];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
signIn = [GPPSignIn sharedInstance];
// You previously set kClientId in the "Initialize the Google+ client" step
signIn.clientID = kClientId;
[signIn setScopes:[NSArray arrayWithObject: #"https://www.googleapis.com/auth/plus.me"]];
// Uncomment to get the user's email
signIn.shouldFetchGoogleUserEmail = YES;
// Uncomment to get the user's ID
signIn.shouldFetchGoogleUserID = YES;
signIn.delegate = self;
Gplusbtn = [[GPPSignInButton alloc] init];
Gplusbtn.frame = CGRectMake([simod CG:10], [simod CG:125], [simod CG:300], [simod CG:30]);
Gplusbtn.style=kGPPSignInButtonStyleWide;
Gplusbtn.enabled = YES;
[self.view addSubview:Gplusbtn];
}
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (error) {
_signInAuthStatus.text =
[NSString stringWithFormat:#"Status: Authentication error: %#", error];
return;
}
NSLog(#"ID:%#", signIn.userID);
}
NSLog show ID:(null)
So where code has a problem, how to fix it?
You just need to use
[GPPSignIn sharedInstance]
like this:
NSString * gpUserID = [GPPSignIn sharedInstance].userID;

Google login in ios with google sdk?

#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];
}

Google Plus login - provide user email redirect to browser/Google Plus app

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];
}

Social Logout Google Plus Issue in iOS

logout from google plus I used disconnect method but after that sign in app directly goes to permission page. Doesn't ask for Login. why?
here is my Sign In function
-(google*) MethodgoogleLogin
{
[[NSNotificationCenter defaultCenter] removeObserver:self name:#"gotGoogleErrorAppClosed" object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(gotGoogleErrorAppClosed:) name:#"gotGoogleErrorAppClosed" object:nil];
obj_google = [[google alloc]init];
personName=[[GTLPlusPersonName alloc]init];
// google + code
signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.shouldFetchGoogleUserID = YES;
signIn.shouldFetchGoogleUserEmail = YES;
signIn.clientID = #"384945330563-pcls0t8c28s1jf7qiod9555sg7edfqhj.apps.googleusercontent.com";
signIn.scopes = #[ kGTLAuthScopePlusLogin ];
signIn.delegate = obj_google;
[signIn authenticate];
return obj_google;
}
here is my sign out function
-(void)signOut
{
[signIn disconnect];
[signIn signOut];
}
You can use the signOut method of the GPPSignIn object to sign out your user, for example:
- (void)signOut {
[[GPPSignIn sharedInstance] signOut];
}
and after this revoke the token and disconnect the app.
For more information visit this:- https://developers.google.com/+/mobile/ios/sign-in#sign_out_the_user

User must be signed in to use the native share box

I want to add share on google-plus property in my application.
I registered client application on google web console and obtained client-id.
In my viewDidLoad function :
- (void)viewDidLoad{
CGRect rect = self.view.bounds;
rect.size.height = rect.size.height - 50;
_postContentUIWV = [[UIWebView alloc] initWithFrame:rect];
[_postContentUIWV loadHTMLString:selectedPostCD.content baseURL:nil];
[self.view addSubview:_postContentUIWV];
self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
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;
[GPPSignIn sharedInstance].actions = [NSArray arrayWithObjects:
#"http://schemas.google.com/AddActivity",
#"http://schemas.google.com/BuyActivity",
#"http://schemas.google.com/CheckInActivity",
#"http://schemas.google.com/CommentActivity",
#"http://schemas.google.com/CreateActivity",
#"http://schemas.google.com/ListenActivity",
#"http://schemas.google.com/ReserveActivity",
#"http://schemas.google.com/ReviewActivity",
nil];
// Uncomment one of these two statements for the scope you chose in the previous step
signIn.scopes = #[ kGTLAuthScopePlusLogin ]; // "https://www.googleapis.com/auth/plus.login" scope
//signIn.scopes = #[ #"profile" ]; // "profile" scope
// Optional: declare signIn.actions, see "app activities"
signIn.delegate = self;
[signIn trySilentAuthentication];
}
Then in my onButtonCLick function:
- (void) googlePlusShareTapped {
id<GPPNativeShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];
[shareBuilder setURLToShare:[NSURL URLWithString:#"https://www.shinnxstudios.com"]];
[shareBuilder setPrefillText:#"This is an awesome G+ Sample to share"];
// [shareBuilder setTitle:#"Title" description:#"Descp" thumbnailURL:[NSURL URLWithString:#"https://www.fbo.com/imageurl"]];
[shareBuilder open];
}
However I get the message:
[lvl=3] -[GPPNativeShareBuilderImpl open] User must be signed in to use the native share box.
I downloaded google+ app from App Store and signed in. But every time I get this message and cannot share anything on google+.
Any suggestions?
First remove your application from simulator then close XCode and reopen and run your app again by changing with following code:
GPPSignIn *signIn = [GPPSignIn sharedInstance];
signIn.shouldFetchGooglePlusUser = YES;
signIn.clientID = kClientId;
signIn.scopes = #[ kGTLAuthScopePlusLogin ];
signIn.delegate = self;
[signIn authenticate];
And also make sure that you have to added GooglePlus.bundle in to your application.

Resources