首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >解析- Facebook用户每次都会被重新创建

解析- Facebook用户每次都会被重新创建
EN

Stack Overflow用户
提问于 2015-04-26 02:22:34
回答 1查看 34关注 0票数 0

我正在使用Parse.com + Facebook用户,我注意到一些以前没有发生过的不同寻常的事情。用户通过Facebook创建帐户,登录,注销,登录,注销,然后当他们尝试登录时,该用户被删除,另一个用户被创建。为什么会这样呢?

这是我的注册/登录代码:

代码语言:javascript
运行
复制
-(IBAction)facebookSignIn:(id)sender{
    CLGeocoder *geo = [[CLGeocoder alloc] init];
    if(![CLLocationManager locationServicesEnabled] || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied ){
        UIAlertView *locationAlert = [[UIAlertView alloc]initWithTitle:@"Oops!" message:@"You must have location services enabled for this app to work properly" delegate:self cancelButtonTitle:nil otherButtonTitles:@"Okay", nil];
        [locationAlert show];
    }else{



        [PFFacebookUtils logInWithPermissions:_permissions block:^(PFUser *aUser, NSError *suError) {
            if(!aUser){
                NSLog(@"not fbook user because %@",[suError description]);

                if([[[suError userInfo] objectForKey:@"com.facebook.sdk:ErrorLoginFailedReason"] isEqualToString:@"com.facebook.sdk:SystemLoginDisallowedWithoutError"]){
                 UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Error" message:@"Looks like you have Facebook authentication disabled! Go to Settings > Facebook > mySwapp and turn the switch ON"delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Okay", nil];
                    [alert show];

                }
                else{
                 UIAlertView  *alert = [[UIAlertView alloc]initWithTitle:@"Error Signing In/Logging In" message:[suError localizedDescription] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"Okay", nil];
                    [alert show];
                }

            }
            else if(aUser.isNew){

                NSLog(@"User is NEW");
                 [[FBRequest requestForMe] startWithCompletionHandler:
                 ^(FBRequestConnection *connection,
                 NSDictionary<FBGraphUser> *user,
                 NSError *fbError) {
                 if (!fbError) {

                 NSLog(@"Facebook Request succeeded");

                 NSString *email = [user objectForKey:@"email"];
                 [aUser setEmail:email];

                 PFQuery *g = [PFQuery queryWithClassName:@"Counter"];
                 PFObject *cool = [g getObjectWithId:@"gpKDgNhwhw"];
                 [cool incrementKey:@"users"];
                 [cool saveEventually];
                 NSString *username = [NSString stringWithFormat:@"blahblah%d",[[cool objectForKey:@"users"] intValue]];
                 [aUser setUsername:username];
                 PFInstallation *installation = [PFInstallation currentInstallation];
                 [installation setObject:aUser forKey:@"user"];

                 [aUser setObject:@NO forKey:@"text"];
                 [aUser setObject:@YES forKey:@"snew"];
                 [aUser setObject:@"All" forKey:@"prefState"];
                 [aUser setObject:@"All" forKey:@"prefCat"];
                     [aUser setObject:@YES forKey:@"fnew"];
                 _type = @"facebook";

                 NSLog(@"Right before geopoint search....");

                 [PFGeoPoint geoPointForCurrentLocationInBackground:^(PFGeoPoint *geoPoint, NSError *error) {
                 if(!error){
                 NSLog(@"Got current geopoint!");
                 CLLocation *myLocation = [[CLLocation alloc]initWithLatitude:geoPoint.latitude longitude:geoPoint.longitude];
                 [geo reverseGeocodeLocation:myLocation completionHandler:^(NSArray *placemarks, NSError *error) {
                 if(!error){
                 CLPlacemark *pl = placemarks[0];

                 NSString *zip = [pl.addressDictionary objectForKey:(NSString *)kABPersonAddressZIPKey];
                 NSString *city = [pl.addressDictionary objectForKey:(NSString *)kABPersonAddressCityKey];
                 NSString *state = [pl.addressDictionary objectForKey:(NSString *)kABPersonAddressStateKey];
                 if(city == nil ||state ==nil){
                 NSLog(@"city or state is nil");
                 if(city==nil){
                 NSLog(@"city is nil");
                 }
                 if(state==nil){
                 NSLog(@"state is nil");
                 }
                 }
                 [aUser setObject:city forKey:@"city"];
                 [aUser setObject:state forKey:@"state"];
                 [aUser setObject:zip forKey:@"zip"];
                 [aUser setObject:geoPoint forKey:@"geopoint"];
                 [aUser setObject:@NO forKey:@"pref"];
                 [aUser setObject:@20 forKey:@"radius"];
                     [aUser setObject:@0 forKey:@"postCount"];

                 [aUser saveInBackgroundWithBlock:^(BOOL succeeded, NSError *perror) {
                 if(!perror && succeeded){

                 [self performSegueWithIdentifier:@"registerMe" sender:self];                                          }
                 else{

                     CCAlertView *errorAlert = [[CCAlertView alloc]initWithTitle:@"Oops!" message:[NSString stringWithFormat:@"%@. If you have already registered, please login regularly and go to the settings tab and switch on \"Link to Facebook\".",[[perror userInfo] objectForKey:@"error"]]];
                     [errorAlert addButtonWithTitle:@"Okay" block:^{
                         [aUser deleteInBackground];
                     }];
                     [errorAlert show];
                 }
                 }];
                 }
                 else{
                     CCAlertView *errorAlert = [[CCAlertView alloc]initWithTitle:@"Error getting Facebook data" message:[[fbError userInfo] objectForKey:@"error"]];
                     [errorAlert addButtonWithTitle:@"Okay" block:^{
                         [aUser deleteInBackground];
                     }];
                     [errorAlert show];

                 }
                 }];
                 }
                 else{
                CCAlertView *errorAlert = [[CCAlertView alloc]initWithTitle:@"Facebook Sign In/Sign Up" message:[[suError userInfo] objectForKey:@"error"]];
                     [errorAlert addButtonWithTitle:@"Okay" block:^{

                         [aUser deleteInBackground];

                     }];


                 [errorAlert show];
                     NSString *ciid = [[PFInstallation currentInstallation] objectId];
                     [PFCloud callFunctionInBackground:@"logError" withParameters:@{@"installation":ciid,@"message":[suError description],@"place":@"Facebook Sign In/Sign Up"} block:^(id object, NSError *error) {
                         if(error){
                             PFObject * errorObj = [PFObject objectWithClassName:@"Error"];
                             [errorObj setObject:ciid forKey:@"installation"];
                             [errorObj setObject:[suError description] forKey:@"message"];
                             [errorObj setObject:@"Facebook Sign In/Sign Up" forKey:@"place"];
                             [errorObj saveEventually];
                         }
                     }];
                 }
                 }];


                 }

                 }];










            }
            else{
                NSLog(@"User is OLD");
                [self performSegueWithIdentifier:@"showMain" sender:self];                        }

        }];





    }

  }

下面是我的注销代码:

代码语言:javascript
运行
复制
- (IBAction)goBackNow:(id)sender {
    NSLog(@"gobacknow called");
    [PFUser logOut];

    [self.navigationController popToRootViewControllerAnimated:YES];

}
EN

回答 1

Stack Overflow用户

发布于 2015-04-27 22:47:13

您可以尝试向logout方法添加更多内容。例如:

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

PFInstallation *installation = [PFInstallation currentInstallation];
installation[@"user"] = [NSNull null];
[installation saveInBackground];

还要记住在示例中使用[installation saveInBackground];

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

https://stackoverflow.com/questions/29868970

复制
相关文章

相似问题

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