Facebook登录后删除[PFUser currentUser]

时间:2014-05-24 13:59:38

标签: ios facebook parse-platform

我想让我的用户能够删除他们的帐户,因此不会显示在其他用户的Feed中。

我可以这样做的一种方法是在“用户”表格中添加“有效”列。

更好的方法是从表中删除其User对象。不幸的是,当我实现代码时,应用程序崩溃并显示以下错误:'除非已经通过logIn或signUp验证了用户,否则无法删除用户。

我的登录代码可能有问题。

NSArray *permissionsArray = @[@"email", @"public_profile", @"user_friends"];

[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
    if (!user) {
        if (error) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Oops, error" message:@"Couldn't login at the moment. Try again later." delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Dismiss", nil];
            [alert show];
        }
    }
    else {
        // Send request to Facebook
        [[FBRequest requestForMe] startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            // handle response
            if (!error) {
                // Parse the data received
                NSDictionary *userData = (NSDictionary *)result;

                [[PFUser currentUser] setObject:[NSNumber numberWithLongLong:[userData[@"id"] longLongValue]] forKey:@"facebook_id"];
                [[PFUser currentUser] setObject:userData[@"name"] forKey:@"name"];
                [[PFUser currentUser] saveInBackground];


                // Go to home screen here
            }
        }];
    }
}];

删除操作如下:

PFObject *userObject = [PFObject objectWithoutDataWithClassName:@"_User" objectId:[PFUser currentUser].objectId];
[userObject deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    // back to login view controller
}];

知道如何解决这个问题吗?

1 个答案:

答案 0 :(得分:4)

为什么在已经将用户对象设置为[PFUser currentUser]时重新获取用户对象?也许您需要直接删除[PFUser currentUser]对象?类似的东西:

[[PFUser currentUser] deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    // back to login view controller
}];