如果facebook登录iOS应用程序的授权被拒绝,如何再次请求电子邮件权限

如果facebook登录iOS应用程序的授权被拒绝,如何再次请求电子邮件权限,ios,objective-c,facebook-graph-api,Ios,Objective C,Facebook Graph Api,在我的应用程序中,有facebook登录。我正在为facebook登录创建自定义用户界面。我正在获取用户的公共配置文件和电子邮件。首次登录facebook时,有一个授权屏幕,如1.jpg所示。在该屏幕中,用户可以选择显示编辑您提供的信息。单击该编辑按钮,用户将被定向到下一屏幕他可以拒绝访问电子邮件。我的问题是,是否有一个规定,编辑您提供的信息按钮是隐藏的,或者是否有任何可能性,用户被要求再次电子邮件权限 我的代码如下: *********Appdelegate.h #import <UI

在我的应用程序中,有facebook登录。我正在为facebook登录创建自定义用户界面。我正在获取用户的公共配置文件和电子邮件。首次登录facebook时,有一个授权屏幕,如1.jpg所示。在该屏幕中,用户可以选择显示编辑您提供的信息。单击该编辑按钮,用户将被定向到下一屏幕他可以拒绝访问电子邮件。我的问题是,是否有一个规定,编辑您提供的信息按钮是隐藏的,或者是否有任何可能性,用户被要求再次电子邮件权限

我的代码如下: *********Appdelegate.h

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>


@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) NSString *strBasePath;
-(void)openActiveSessionWithPermissions:(NSArray *)permissions allowLoginUI:(BOOL)allowLoginUI;

@end

******Appdelegate.m


#import "AppDelegate.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
// Override point for customization after application launch.



return YES;
}

-(void)openActiveSessionWithPermissions:(NSArray *)permissions allowLoginUI:(BOOL)allowLoginUI{
[FBSession openActiveSessionWithReadPermissions:permissions
                                   allowLoginUI:allowLoginUI
                              completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {

                                  // Create a NSDictionary object and set the parameter values.
                                  NSDictionary *sessionStateInfo = [[NSDictionary alloc] initWithObjectsAndKeys:
                                                                    session, @"session",
                                                                    [NSNumber numberWithInteger:status], @"state",
                                                                    error, @"error",
                                                                    nil];

                                  // Create a new notification, add the sessionStateInfo dictionary to it and post it.
                                  [[NSNotificationCenter defaultCenter] postNotificationName:@"SessionStateChangeNotification"
                                                                                      object:nil
                                                                                    userInfo:sessionStateInfo];

                              }];
}

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}

 - (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.

if ([FBSession activeSession].state == FBSessionStateCreatedTokenLoaded) {
    [self openActiveSessionWithPermissions:nil allowLoginUI:NO];
}

[FBAppCall handleDidBecomeActive];

}
#import "ViewController.h"
#import "AppDelegate.h"
#import <QuartzCore/QuartzCore.h>
#import <FacebookSDK/FacebookSDK.h>

@interface ViewController ()

@property (nonatomic, strong) AppDelegate *appDelegate;

-(void)hideUserInfo:(BOOL)shouldHide;

-(void)handleFBSessionStateChangeWithNotification:(NSNotification *)notification;

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];


self.imgProfilePicture.layer.masksToBounds = YES;
self.imgProfilePicture.layer.cornerRadius = 30.0;
self.imgProfilePicture.layer.borderColor = [UIColor whiteColor].CGColor;
self.imgProfilePicture.layer.borderWidth = 1.0;

[self hideUserInfo:YES];
self.activityIndicator.hidden = YES;

self.appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleFBSessionStateChangeWithNotification:) name:@"SessionStateChangeNotification" object:nil];



}

-(void)hideUserInfo:(BOOL)shouldHide{
self.imgProfilePicture.hidden = shouldHide;
self.lblFullname.hidden = shouldHide;
self.lblEmail.hidden = shouldHide;
}

- (IBAction)toggleLoginState:(id)sender {
if ([FBSession activeSession].state != FBSessionStateOpen &&
    [FBSession activeSession].state != FBSessionStateOpenTokenExtended) {

[self.appDelegate openActiveSessionWithPermissions:@[@"public_profile", @"email"] allowLoginUI:YES];


}
else{
    // Close an existing session.
    [[FBSession activeSession] closeAndClearTokenInformation];

    // Update the UI.
    [self hideUserInfo:YES];
    self.lblStatus.hidden = NO;
    self.lblStatus.text = @"You are not logged in.";
  }

  }

 -(void)handleFBSessionStateChangeWithNotification:(NSNotification *)notification{
// Get the session, state and error values from the notification's userInfo dictionary.
NSDictionary *userInfo = [notification userInfo];

FBSessionState sessionState = [[userInfo objectForKey:@"state"] integerValue];
NSError *error = [userInfo objectForKey:@"error"];

self.lblStatus.text = @"Logging you in...";
[self.activityIndicator startAnimating];
self.activityIndicator.hidden = NO;

// Handle the session state.
// Usually, the only interesting states are the opened session, the closed session and the failed login.
if (!error) {
    // In case that there's not any error, then check if the session opened or closed.
    if (sessionState == FBSessionStateOpen) {
        // The session is open. Get the user information and update the UI.
        [FBRequestConnection startWithGraphPath:@"me"
                                     parameters:@{@"fields": @"first_name, last_name, picture.type(normal), email"}
                                     HTTPMethod:@"GET"
                              completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                  if (!error) {

                                      // Set the use full name.
                                      self.lblFullname.text = [NSString stringWithFormat:@"%@ %@",
                                                               [result objectForKey:@"first_name"],
                                                               [result objectForKey:@"last_name"]
                                                               ];

                                      // Set the e-mail address.
                                      self.lblEmail.text = [result objectForKey:@"email"];

                                      // Get the user's profile picture.
                                      NSURL *pictureURL = [NSURL URLWithString:[[[result objectForKey:@"picture"] objectForKey:@"data"] objectForKey:@"url"]];
                                      self.imgProfilePicture.image = [UIImage imageWithData:[NSData dataWithContentsOfURL:pictureURL]];


                                      strFbEmail=[result objectForKey:@"email"];

                                      strFbFirstName=[result objectForKey:@"first_name"];
                                      strFbLastName=[result objectForKey:@"last_name"];
                                      strFbAccessToken = [[[FBSession activeSession] accessTokenData] accessToken];
                                      NSLog(@"%@ -------- %@ -------- %@ -------%@",strFbAccessToken,strFbEmail,strFbFirstName,strFbLastName);

                                      //[self sendFbData];
                                      // Make the user info visible.
                                      [self hideUserInfo:NO];

                                      // Stop the activity indicator from animating and hide the status label.
                                      self.lblStatus.hidden = YES;
                                      [self.activityIndicator stopAnimating];
                                      self.activityIndicator.hidden = YES;
                                  }
                                  else{
                                      NSLog(@"%@", [error localizedDescription]);
                                  }
                              }];

        [self.btnToggleLoginState setTitle:@"Logout" forState:UIControlStateNormal];
    }
    else if (sessionState == FBSessionStateClosed || sessionState == FBSessionStateClosedLoginFailed){
        // A session was closed or the login was failed. Update the UI accordingly.
        [self.btnToggleLoginState setTitle:@"Login" forState:UIControlStateNormal];
        self.lblStatus.text = @"You are not logged in.";
        self.activityIndicator.hidden = YES;
    }
}
else{
    // In case an error has occurred, then just log the error and update the UI accordingly.
    NSLog(@"Error: %@", [error localizedDescription]);
    [self hideUserInfo:YES];        
    [self.btnToggleLoginState setTitle:@"Login" forState:UIControlStateNormal];

}


}
#导入
#进口
@接口AppDelegate:UIResponder
@属性(强,非原子)UIWindow*window;
@属性(强,非原子)NSString*STRBSEPATH;
-(void)openActiveSessionWithPermissions:(NSArray*)权限allowLoginUI:(BOOL)allowLoginUI;
@结束
******Appdelegate.m
#导入“AppDelegate.h”
@实现AppDelegate
-(BOOL)应用程序:(UIApplication*)应用程序使用选项完成启动:(NSDictionary*)启动选项
{
//应用程序启动后自定义的覆盖点。
返回YES;
}
-(void)openActiveSessionWithPermissions:(NSArray*)权限allowLoginUI:(BOOL)allowLoginUI{
[FBSession openActiveSessionWithReadPermissions:权限
allowLoginUI:allowLoginUI
completionHandler:^(FBSession*会话,FBSessionState状态,N错误*错误){
//创建NSDictionary对象并设置参数值。
NSDictionary*sessionStateInfo=[[NSDictionary alloc]initWithObjectsAndKeys:
会话,@“会话”,
[NSNumber numberWithInteger:状态],@“状态”,
错误,@“错误”,
零];
//创建一个新通知,将sessionStateInfo字典添加到其中并发布。
[[NSNotificationCenter defaultCenter]postNotificationName:@“SessionStateChangeNotification”
对象:无
userInfo:sessionStateInfo];
}];
}
-(BOOL)应用程序:(UIApplication*)应用程序openURL:(NSURL*)url源应用程序:(NSString*)源应用程序注释:(id)注释{
返回[FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}
-(无效)应用IDBECOMEACTIVE:(UIApplication*)应用
{
//重新启动应用程序处于非活动状态时暂停(或尚未启动)的所有任务。如果应用程序以前位于后台,可以选择刷新用户界面。
if([FBSession activeSession].state==FBSessionStateCreatedTokenLoaded){
[self-openActiveSessionWithPermissions:nil allowLoginUI:NO];
}
[FBAppCall handleDidBecomeActive];
}
#导入“ViewController.h”
#导入“AppDelegate.h”
#进口
#进口
@界面视图控制器()
@属性(非原子,强)AppDelegate*AppDelegate;
-(void)hideUserInfo:(BOOL)应该隐藏;
-(作废)handleFBSessionStateChangeWithNotification:(NSNotification*)通知;
@结束
@实现视图控制器
-(无效)viewDidLoad
{
[超级视图下载];
//加载视图后,通常从nib执行任何其他设置。
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent];
self.imgProfilePicture.layer.masksToBounds=是;
self.imgProfilePicture.layer.cornerRadius=30.0;
self.imgProfilePicture.layer.borderColor=[UIColor whiteColor].CGColor;
self.imgProfilePicture.layer.borderWidth=1.0;
[自我隐藏信息:是];
self.activityIndicator.hidden=是;
self.appDelegate=(appDelegate*)[[UIApplication sharedApplication]delegate];
[[NSNotificationCenter defaultCenter]添加观察者:自选择器:@selector(handleFBSessionStateChangeWithNotification:)名称:@“SessionStateChangeNotification”对象:nil];
}
-(无效)hideUserInfo:(BOOL)应该隐藏{
self.imgProfilePicture.hidden=shouldHide;
self.lblFullname.hidden=shoulhdide;
self.lblEmail.hidden=应隐藏;
}
-(iAction)toggleLoginState:(id)发送方{
如果([FBSession activeSession].state!=FBSessionStateOpen&&
[FBSession activeSession].state!=FBSessionStateOpenTokenExtended){
[self.appDelegate openActiveSessionWithPermissions:@[@“public_profile”,“email”]allowLoginUI:YES];
}
否则{
//关闭现有会话。
[[FBSession activeSession]closeAndClearTokenInformation];
//更新用户界面。
[自我隐藏信息:是];
self.lblStatus.hidden=否;
self.lblStatus.text=@“您未登录。”;
}
}
-(无效)handleFBSessionStateChangeWithNotification:(NSNotification*)通知{
//从通知的userInfo字典中获取会话、状态和错误值。
NSDictionary*userInfo=[notification userInfo];
FBSessionState sessionState=[[userInfo objectForKey:@“state”]integerValue];
N错误*错误=[userInfo objectForKey:@“错误”];
self.lblStatus.text=@“让您登录…”;
[self.activityIndicator startAnimating];
self.activityIndicator.hidden=否;
//处理会话状态。
//通常,唯一有趣的状态是打开的会话、关闭的会话和失败的登录。
如果(!错误){
//如果没有任何错误,则检查会话是否打开或关闭。
if(sessionState==FBSessionStateOpen){
//会话已打开。获取用户信息并更新UI。
[FBRequestConnection startWithGraphPath:@“我”
参数:@{@“字段”:@“名、姓、,
if ([FBSession.activeSession.permissions indexOfObject:@"email"] == NSNotFound) {
    [FBSession.activeSession requestNewReadPermissions:@[@"email"]
                         completionHandler:^(FBSession *session,
                                             NSError *error) 
    {
         // Handle new permissions callback
    }];
} else {
    // permission exists
}