在致电GPPSignIn
之前,有没有办法向[self.signIn authenticate];
对象提供用户电子邮件,以便用户无需在浏览器/ Google Plus应用中输入该网址即可使用Google帐户登录?我想将用户电子邮件传递给登录表单,以便用户只需输入密码即可。我之前要求用户提供电子邮件,因此在大多数情况下我可以使用它来帮助他以更少的步骤登录。 self.signIn.userEmail
是只读的,所以对我没什么帮助。
答案 0 :(得分:0)
如果第一次不需要,用户需要输入电子邮件和密码。
- (IBAction)Btn_gogleShare:(id)sender {
if ([[GPPSignIn sharedInstance] authentication]) {
NSLog(@"share");
[self GoogleShare];
} else {
NSLog(@"Login");
[self GoogleLogin];
}
}
#pragma mark - Google+所有活动
#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];
}