FBRequestConnection startForMeWithCompletionHandler - NSInvalidArgumentException

时间:2014-08-01 14:48:30

标签: ios facebook parse-platform

我似乎无法在没有抛出异常的情况下调用FBRequestConnection startForMeWithCompletionHandler

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Can't use nil for keys or values on PFObject. Use NSNull for values.'

这曾经没有任何问题。但后来我删除了"用户"我的解析表中的对象。现在每当我尝试登录时,新用户都会在解析表中创建,我会收到用户登录的日志消息。但是当我想调用FBRequestConnection函数来检索用户的facebook id时,我得到了错误

- (id) init {
   if (self == [super init]) {
    [PFFacebookUtils initializeFacebook];
    sharedHelper = self;
   }
   return self;
}

- (void) authenticateUserWithFacebook {
NSArray *permissionsArray = @[@"user_relationships",@"user_friends",@"read_friendlists"];

[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {

    if (!user) {
        if (!error) {
            NSLog(@"Uh oh. The user cancelled the Facebook login.");
        } else {
            NSLog(@"Uh oh. An error occurred: %@", error);
            [[PFFacebookUtils session] closeAndClearTokenInformation];
            [[PFFacebookUtils session] close];
            [[FBSession activeSession] closeAndClearTokenInformation];
            [[FBSession activeSession] close];
            [FBSession setActiveSession:nil];
            [PFUser logOut];
        }
    } else if (user.isNew) {
        NSLog(@"User with facebook signed up and logged in!");
        UIApplication *application = [UIApplication sharedApplication];
        [application registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];

        [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            [[PFUser currentUser] setObject:[result valueForKey:@"id"] forKey:kFbIdKey];
            [[PFUser currentUser] setObject:[result valueForKey:@"name"] forKey:@"name"];
            [[PFUser currentUser] saveInBackground];
        }];
    } else {
        NSLog(@"User with facebook logged in!");
        UIApplication *application = [UIApplication sharedApplication];
        [application registerForRemoteNotificationTypes: UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert | UIRemoteNotificationTypeSound];

        [FBRequestConnection startForMeWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
            [[PFUser currentUser] setObject:[result valueForKey:@"id"] forKey:kFbIdKey];
            [[PFUser currentUser] setObject:[result valueForKey:@"name"] forKey:@"name"];
            [[PFUser currentUser] saveInBackground];
        }];
    }
   }];
 }

1 个答案:

答案 0 :(得分:0)

我想我已经使用[FBSession renewSystemCredentials:]解决了这个问题 并删除并重新安装该应用程序。我认为我也删除了Installation个对象也与此问题有关。