ios - objective-c - 如果 ios 的电子邮件 ID 为空,则登录后的 UIAlertView 输入电子邮件 ID

标签 ios facebook email facebook-login

在我的代码中,如果用户使用手机号码登录,有时我会在使用 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/

相关文章:

ios - 在 Alamofire 中快速发送 GET 请求中的 json 对象

ios - clipsToBounds 如何工作?

android - 如何建立从 iOS 到 Android 设备的 RFCOMM 蓝牙连接

facebook - 按表格列出 Facebook 线索广告问题

iOS App - 使用 Swift 在后台发送邮件

ios - 如何知道推送通知发送状态

php - 如何首先获取最近的记录?

android - Xamarin Android 应用无法初始化 Facebook SDK

c# - 以用户别名发送消息

html - 如何使用 Perl 发送 HTML 电子邮件?