Facebook登录后删除[PFUser currentUser] [英] Delete [PFUser currentUser] after Facebook login
问题描述
我想让我的用户能够删除他们的帐户,从而不会出现在其他用户的供稿中.
I want to give my user the ability to remove their account, thus not showing up in the feeds of other users.
我可以这样做的一种方法是在用户"表中添加活动"列.
One way I could do this is adding an 'active' column to the 'User' table.
更好的方法是从表中删除其User对象.不幸的是,当我执行此操作时,应用程序崩溃,并显示以下错误:除非已通过登录或注册身份验证,否则无法删除用户."
A better way would be to remove their User object from the table. Unfortunately, when I implement code to do so, the app crashes and the following error shows up: 'User cannot be deleted unless they have been authenticated via logIn or signUp'.
也许我的登录代码有问题.
Maybe something is wrong with my login code.
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
}];
有什么办法解决这个问题吗?
Any idea how to fix this?
推荐答案
为什么已经以[PFUser currentUser]
的身份重新获取用户对象?也许您需要直接删除[PFUser currentUser]
对象?像这样:
Why are you re-fetching the user object when you already have it as [PFUser currentUser]
? Perhaps you need to delete the [PFUser currentUser]
object directly? Something like:
[[PFUser currentUser] deleteInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
// back to login view controller
}];
这篇关于Facebook登录后删除[PFUser currentUser]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!