在我的代码中,如果用户使用手机号码登录,有时我会在使用 facebook 登录时得到电子邮件 ID 的空值
所以我希望 uialertview 输入电子邮件 ID 并传递到我的 api 链接
- (void) fetchFacebookUserInfo {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"first_name, last_name, picture.type(large), email, name, id, gender"} ]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
NSLog(@"name:%@",[result objectForKey:@"name"]);
NSLog(@"id:%@",[result objectForKey:@"id"]);
NSLog(@"email:%@",[result objectForKey:@"email"]);
if ([result objectForKey:@"email"]==NULL) {
// here i want uialertview for enter email id with validation and pass email id to my Callapi
}
} else {
[self CallApi:[result objectForKey:@"name"] :[result objectForKey:@"email"]];
}
}
}];
}
}
最佳答案
在ViewController.h文件中定义strName
NSString *strName;
现在在你的方法中:-
- (void) fetchFacebookUserInfo {
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"first_name, last_name, picture.type(large), email, name, id, gender"} ]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result);
NSLog(@"name:%@",[result objectForKey:@"name"]);
NSLog(@"id:%@",[result objectForKey:@"id"]);
NSLog(@"email:%@",[result objectForKey:@"email"]);
strName = [result objectForKey:@"name"];
if ([result objectForKey:@"email"]==NULL) {
UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:APP_NAME message:@"Please enter email id" delegate:self cancelButtonTitle:@"Submit" otherButtonTitles:@"Cancel", nil];
alertView.alertViewStyle = UIAlertViewStylePlainTextInput;
[alertView show];
}
} else {
[self CallApi:strName:[result objectForKey:@"email"]];
}
}
}];
}
}
**请确保您已在界面(.h 文件)中设置 AlertViewDelegate,如下所示**
@interface yourViewController:UIViewController<UIAlertViewDelegate>
现在使用 UIAlertView 的委托(delegate)方法,如下所示:-
-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 0){
if(![CommonMethod validateEmailWithString:[alertView textFieldAtIndex:0].text]){
NsLog(@"Please enter valid email address");
}else{
[self callYourWebService:strName:[alertViewAtIndex:0].text];
}
}
}
希望这对您有所帮助,让您开心。
关于ios - objective-c - 如果 ios 的电子邮件 ID 为空,则登录后的 UIAlertView 输入电子邮件 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35170162/