다음은 Google 계정에서 데이터를 가져 오는 데 사용하는 코드입니다. 로그인 ID로 다른보기에서 이메일 주소를 사용하고 싶습니다.json에서 검색 한 데이터를 한 뷰에서 다른 뷰로 전달하는 방법은 무엇입니까?
이 코드는 내 FirstViewController
에 있으며 다른보기에서 이메일을 사용하고 싶습니다.
여기
- (void)finishedWithAuth:(GTMOAuth2Authentication *)auth
error:(NSError *)error {
if (error) {
return;
}
NSString *accessTocken = [auth valueForKey:@"accessToken"]; // access tocken pass in .pch file
NSLog(@"%@",accessTocken);
NSString *str=[NSString stringWithFormat:@"https://www.googleapis.com/oauth2/v1/userinfo?access_token=%@",accessTocken];
NSString *escapedUrl = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"%@",escapedUrl]];
NSString *jsonData = [[NSString alloc] initWithContentsOfURL:url usedEncoding:nil error:nil];
NSDictionary *jsonDictionary = [NSJSONSerialization JSONObjectWithData:[jsonData dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingMutableContainers error:&error];
NSString *userId=[jsonDictionary objectForKey:@"email"];
NSLog(@" user data %@",jsonData);
NSLog(@"Received Access Token:%@",auth);
NSLog(@"email id : %@ ",userId);
GTLServicePlus* plusService = [[GTLServicePlus alloc] init];
plusService.retryEnabled = YES;
[plusService setAuthorizer:auth];
GTLQueryPlus *query = [GTLQueryPlus queryForPeopleGetWithUserId:userId];
[plusService executeQuery:query completionHandler:^(GTLServiceTicket *ticket,GTLPlusPerson *person,NSError *error) {
if (error) {
GTMLoggerError(@"Error: %@", error);
} else {
// Retrieve the display name and "about me" text
// [person retain];
NSString *description = [NSString stringWithFormat:
@"%@\n%@", person.displayName,
person.aboutMe];
GTLPlusPersonImage *image =person.image;
NSString *strimag=[image valueForKey:@"url"];
// [self setImageFromURL:[NSURL URLWithString:strimag]];
NSData *receivedData = [NSData dataWithContentsOfURL:[NSURL URLWithString:strimag]];
UIImage *img = [[UIImage alloc] initWithData:receivedData ];
receivedData=UIImageJPEGRepresentation(img,50);
NSLog(@"description %@",description);
}
}];
if ([GPPSignIn sharedInstance] == true) {
[self performSegueWithIdentifier:@"pass" sender:self];
}
[[GPPSignIn sharedInstance] signOut];
}
당신이 prepareforsegue의 사용 코드를 보여줄 수 또는 목적지의 ViewController의 이름을 적어주세요 수 있습니까? –
@NiravD CreatePasswordViewController 그것은 Google 계정에서 값을 가져오고 새 계정을 만들 때 전자 메일을 사용하려고 할 때 이걸 탐색해야합니다. –