iOS Facebook登录“对象无效”崩溃

时间:2013-08-27 20:29:49

标签: ios facebook authentication

使用Facebook 3.7 for iOS,App的身份验证。它占70%的时间,其他30%的崩溃。似乎与是否在互联网上连接没有关系。在下面的第一个方法 - populateUserDetails中,我检查字典是否为nil,我认为这会阻止这个问题,但它仍然会发生。

这是我的错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** setObjectForKey: object cannot be nil (key: 0_auth_logger_id)'

这是我的身份验证码:

- (void)populateUserDetails
{
if (FBSession.activeSession.isOpen) {
    [[FBRequest requestForMe] startWithCompletionHandler:
     ^(FBRequestConnection *connection,
       NSDictionary<FBGraphUser> *user,
       NSError *error) {
         if (!error || ![user isEqualToDictionary: nil]) {
             // if (!error) {
             self.userNameLabel.text = [user objectForKey:@"email"];
             email = [user objectForKey:@"email"];
             //      self.userProfileImage.profileID = user.id;

             if ([facebookUser isEqualToString:@"yes"]){
             [self appendAndSaveData];
             [self performSegueWithIdentifier:@"segueIntroScreenLogin" sender:self];
             }

         }
     }];
}
}

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];

if (FBSession.activeSession.isOpen) {
[self populateUserDetails];
}
}

-(void)logoutButtonWasPressed:(id)sender {
[FBSession.activeSession closeAndClearTokenInformation];
}


- (IBAction)performLogin:(id)sender
{
 facebookUser = @"yes";
 NSLog(@"IntroScreen, email: %@", email);
 AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
 [appDelegate openSession];

    if([email length] >0){

     [self appendAndSaveData];
     [self performSegueWithIdentifier:@"segueIntroScreenLogin" sender:self];
 }

}

2 个答案:

答案 0 :(得分:0)

虽然您的代码中似乎没有引用在NSMutableDictionary中设置值,但是终止消息可能是指您无法将nil作为setObject:forKey:方法的键传递的事实。发布堆栈跟踪会很有帮助但是在缺少的情况下,查找对setObject:forKey的调用并验证forKey参数是否为非零。

答案 1 :(得分:0)

试试这个:

  1. 在您喜欢的编辑器中打开:

    [facebook_sdk_folder]/src/FBSession.m
    
  2. 在第930-940行附近,您将找到以下代码

    if (permissions != nil) {
      NSString* scope = [permissions componentsJoinedByString:@","];
      [params setValue:scope forKey:@"scope"];
    }
    

    将其更改为

    if (permissions != nil) {
      NSString* scope = [permissions componentsJoinedByString:@","];
      if( scope )  // << add this line
        [params setValue:scope forKey:@"scope"];
    }
    

    然后再次重建框架

    [facebook_sdk_folder]/scripts/build_framework.sh
    

    (确保[facebook_sdk_folder] /build/FacebookSDK.framework中新生成的框架是项目中包含的框架)