简体   繁体   中英

Facebook login issue in iOS with latest SDK

I'm implementing app with face book login. i need to access user "public profile" and as well as "email id" also. Here email id is must. i am able to login but after enter login details it shows review page, in that review page it shows "Edit info you provide" button, here i am facing issue. i have 2 doubts here 1) is it possible to disable "edit info you provide" option (or) 2) is it possible to disable user interaction for email field like public profile. my code is below.

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

    [self toggleHiddenState:YES];
    self.lblLoginStatus.text = @"";

    self.loginButton.delegate = self;
    self.loginButton.readPermissions = @[@"public_profile",@"email"];
}
#pragma mark - Private method implementation

-(void)toggleHiddenState:(BOOL)shouldHide{
    self.lblUsername.hidden = shouldHide;
    self.lblEmail.hidden = shouldHide;
    self.profilePicture.hidden = shouldHide;
}


#pragma mark - FBLoginView Delegate method implementation

-(void)loginViewShowingLoggedInUser:(FBLoginView *)loginView{
    self.lblLoginStatus.text = @"You are logged in.";

    [self toggleHiddenState:NO];
}


-(void)loginViewFetchedUserInfo:(FBLoginView *)loginView user:(id<FBGraphUser>)user{
    NSLog(@"%@", user);
    self.profilePicture.profileID = user.id;
    self.lblUsername.text = user.name;
    self.lblEmail.text = [user objectForKey:@"email"];
}


-(void)loginViewShowingLoggedOutUser:(FBLoginView *)loginView{
    self.lblLoginStatus.text = @"You are logged out";

    [self toggleHiddenState:YES];
}


-(void)loginView:(FBLoginView *)loginView handleError:(NSError *)error{
    NSLog(@"%@", [error localizedDescription]);
}

在此处输入图片说明

As far as I read from the documentation in developers.facebook.com for the first and second doubt the answer is No. The user can revoke permission even after he gave permission initially, it is a security feature added from facebook. What you can do is check what permission is granted to you with:

[FBRequestConnection startWithGraphPath:@"/me/permissions" completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
__block NSString *alertText;
__block NSString *alertTitle;
if (!error){
    // Walk the list of permissions looking to see if email has been granted
    NSArray *permissions = (NSArray *)[result data];
    BOOL emailPermission = FALSE;
    for (NSDictionary *perm in permissions) {
        if ([[perm objectForKey:@"permission"] isEqualToString:@"email"] &&
            [[perm objectForKey:@"status"] isEqualToString:@"granted"]) {
            emailPermission = TRUE;
            NSLog(@"email granted.");
            break;
        }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM