Parse - Facebook用户每次都在重建

时间:2015-04-25 18:22:34

标签: ios facebook parse-platform

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

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

-(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];                        }

        }];





    }

  }

这是我的退出代码:

- (IBAction)goBackNow:(id)sender {
    NSLog(@"gobacknow called");
    [PFUser logOut];

    [self.navigationController popToRootViewControllerAnimated:YES];

}

1 个答案:

答案 0 :(得分:0)

您可以尝试向注销方法添加更多内容。 e.g。

[installation saveInBackground];

另请记住示例中的<?php $valid_code = '3471'; $ok = true; if (isset($_POST['code']) && is_string($_POST['code'])) { if (substr($_POST['code'], 0, strlen($valid_code)) === $valid_code) { header('Location: http://sample.web/'); die(); } $ok = false; } ?> <!-- some html here--> <?php if (!$ok):?> <p style="color:red">Wrong code</p> <?php endif;?> <form method="post"> <input name="code"> <input type="submit" value="Check"> </form>