使用适用于 iOS 的 Facebook 3.7,对 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];
}
}