【发布时间】:2014-08-01 14:48:30
【问题描述】:
如果不引发异常,我似乎无法调用 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];
}];
}
}];
}
【问题讨论】:
标签: ios facebook parse-platform