首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >当用户退出我的iOS应用程序时,当他们下一次尝试使用Facebook登录时,他们必须重新输入他们的登录凭据。

当用户退出我的iOS应用程序时,当他们下一次尝试使用Facebook登录时,他们必须重新输入他们的登录凭据。
EN

Stack Overflow用户
提问于 2014-06-13 04:22:20
回答 3查看 1.1K关注 0票数 1

我正在用Parse和Facebook框架构建一个iOS应用程序。

我将用户登录到

代码语言:javascript
运行
复制
-(void)updateUserInformation
{

    FBRequest *request = [FBRequest requestForMe];

    [request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {

        if (!error){

            NSDictionary *userDictionary = (NSDictionary *)result;

            NSString *facebookID = userDictionary[@"id"];
            NSURL *pictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookID]];

            NSMutableDictionary *userProfile = [[NSMutableDictionary alloc]initWithCapacity:8];
            if (userDictionary[@"name"]){
                userProfile[kJFUserProfileNameKey] = userDictionary[@"name"];
            }
            if (userDictionary[@"first_name"]){
                userProfile[kJFUserProfileFirstNameKey] = userDictionary[@"first_name"];
            }
            if (userDictionary[@"location"][@"name"]){
                userProfile[kJFUserProfileLocationKey] = userDictionary[@"location"][@"name"];
            }
            if (userDictionary[@"gender"]){
                userProfile[kJFUserProfileGenderKey] = userDictionary[@"gender"];
            }
            if (userDictionary[@"birthday"]){
                userProfile[kJFUserProfileBirthdayKey] = userDictionary[@"birthday"];
                NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
                [formatter setDateStyle:NSDateFormatterShortStyle];
                NSDate *date = [formatter dateFromString:userDictionary[@"birthday"]];
                NSDate *now = [NSDate date];
                NSTimeInterval seconds = [now timeIntervalSinceDate:date];
                int age = seconds / 31536000;
                userProfile[kJFUserProfileAgeKey] = @(age);
            }
            if (userDictionary[@"interested_in"]){
                userProfile[kJFUserProfileInterestedInKey] = userDictionary[@"interested_in"];
            }
            if (userDictionary[@"relationship_status"]){
                userProfile[kJFUserProfileRelationshipStatusKey] = userDictionary[@"relationship_status"];
            }
            if ([pictureURL absoluteString]){
                userProfile[kJFUserProfilePictureURL] = [pictureURL absoluteString];
            }

            [[PFUser currentUser] setObject:userProfile forKey:kJFUserProfileKey];
            [[PFUser currentUser] saveInBackground];

        }

    }];

}

#pragma mark - from initial login controller



- (IBAction)loginWithFBButtonPressed:(UIButton *)sender {

    NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location", @"user_friends"];

    [PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
        [_activityIndicator stopAnimating]; // Hide loading indicator

        if (!user) {
            if (!error) {
                NSLog(@"Uh oh. The user cancelled the Facebook login.");
            } else {
                NSLog(@"Uh oh. An error occurred: %@", error);
            }
        } else{
            [self performSegueWithIdentifier:@"loginToMainSegue" sender:self];
            [self updateUserInformation];
        }
    }];

}

输入或输出用户没有问题。但是,当我将用户注销并弹出到根视图控制器(使用“用Facebook登录”按钮的那个控制器)时,如果我单击该按钮,Facebook将在Safari选项卡上打开,而上一个用户的Facebook帐户已经激活。用户不必输入登录信息,而是获得消息“您已经授权了thisApp”和“取消”和“确定”按钮。

注销按钮发生在TableViewController中。

更新1

即使实现了这些额外的方法,我的用户仍然登录到Facebook。我尝试了unLink方法,但这似乎并不是我想要的,因为在这样做之后,当我将用户重新登录时,用户的应用程序内数据就不再是他的了。

代码语言:javascript
运行
复制
if (indexPath.row == 3) {
    identifier = nil;

    NSLog(@"pressed logout");

    [PFUser logOut];
    [[PFFacebookUtils session]closeAndClearTokenInformation];
    [[PFFacebookUtils session]close];
    [[FBSession activeSession]closeAndClearTokenInformation];
    [[FBSession activeSession]close];
    [FBSession setActiveSession:nil];

    [self.navigationController popToRootViewControllerAnimated:YES];
}

我要做些什么才能让用户真正从手机上登录到Facebook上,而不是仅仅从当前的应用程序中登录呢?

EN

回答 3

Stack Overflow用户

发布于 2014-06-13 05:06:26

嗨,不知道您使用的是哪个Facebook,但通常从Facebook注销时,您必须清除令牌信息并关闭会话,参考developers.facebook和下面的链接。

http://developers.facebook.com/docs/reference/ios/3.0/class/FBSession/

http://developers.facebook.com/docs/reference/ios/3.0/class/FBSession/#close

代码语言:javascript
运行
复制
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession setActiveSession:nil];

你亦可查核这两个与你的问题有关的问题:-

Facebook图形api注销不工作

Facebook iOS SDK 3.1.1 "closeAndClearTokenInformation“方法无效

希望它对你有帮助

票数 1
EN

Stack Overflow用户

发布于 2014-06-13 05:02:56

在注销之前,尝试从Facebook断开用户对象的链接。

代码语言:javascript
运行
复制
[PFFacebookUtils unlinkUserInBackground:[PFUser currentUser] block:^(BOOL Success,NSError *unlinkError){
                    if(!unlinkError){
                        // User unlinked
                    }else{
                       // Erro while unlink user
                    }
                }];
票数 0
EN

Stack Overflow用户

发布于 2014-06-13 23:12:37

您的应用程序可以选择使用Facebook登录,并控制登录/退出您的应用程序。

如果需要的话,登录他们的Facebook账户是通过代理完成的,但是你不能将他们从Facebook登录出去,因为这会影响所有其他使用Facebook的应用程序。

如果用户想注销Facebook,他们要么使用Facebook应用程序,要么在设备上的设置中使用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24197674

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档