我正在用Parse和Facebook框架构建一个iOS应用程序。
我将用户登录到
-(void)updateUserInformation
{
FBRequest *request = [FBRequest requestForMe];
[request startWithCompletionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
if (!error){
NSDictionary *userDictionary = (NSDictionary *)result;
NSString *facebookID = userDictionary[@"id"];
NSURL *pictureURL = [NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large&return_ssl_resources=1", facebookID]];
NSMutableDictionary *userProfile = [[NSMutableDictionary alloc]initWithCapacity:8];
if (userDictionary[@"name"]){
userProfile[kJFUserProfileNameKey] = userDictionary[@"name"];
}
if (userDictionary[@"first_name"]){
userProfile[kJFUserProfileFirstNameKey] = userDictionary[@"first_name"];
}
if (userDictionary[@"location"][@"name"]){
userProfile[kJFUserProfileLocationKey] = userDictionary[@"location"][@"name"];
}
if (userDictionary[@"gender"]){
userProfile[kJFUserProfileGenderKey] = userDictionary[@"gender"];
}
if (userDictionary[@"birthday"]){
userProfile[kJFUserProfileBirthdayKey] = userDictionary[@"birthday"];
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateStyle:NSDateFormatterShortStyle];
NSDate *date = [formatter dateFromString:userDictionary[@"birthday"]];
NSDate *now = [NSDate date];
NSTimeInterval seconds = [now timeIntervalSinceDate:date];
int age = seconds / 31536000;
userProfile[kJFUserProfileAgeKey] = @(age);
}
if (userDictionary[@"interested_in"]){
userProfile[kJFUserProfileInterestedInKey] = userDictionary[@"interested_in"];
}
if (userDictionary[@"relationship_status"]){
userProfile[kJFUserProfileRelationshipStatusKey] = userDictionary[@"relationship_status"];
}
if ([pictureURL absoluteString]){
userProfile[kJFUserProfilePictureURL] = [pictureURL absoluteString];
}
[[PFUser currentUser] setObject:userProfile forKey:kJFUserProfileKey];
[[PFUser currentUser] saveInBackground];
}
}];
}
#pragma mark - from initial login controller
- (IBAction)loginWithFBButtonPressed:(UIButton *)sender {
NSArray *permissionsArray = @[ @"user_about_me", @"user_relationships", @"user_birthday", @"user_location", @"user_friends"];
[PFFacebookUtils logInWithPermissions:permissionsArray block:^(PFUser *user, NSError *error) {
[_activityIndicator stopAnimating]; // Hide loading indicator
if (!user) {
if (!error) {
NSLog(@"Uh oh. The user cancelled the Facebook login.");
} else {
NSLog(@"Uh oh. An error occurred: %@", error);
}
} else{
[self performSegueWithIdentifier:@"loginToMainSegue" sender:self];
[self updateUserInformation];
}
}];
}输入或输出用户没有问题。但是,当我将用户注销并弹出到根视图控制器(使用“用Facebook登录”按钮的那个控制器)时,如果我单击该按钮,Facebook将在Safari选项卡上打开,而上一个用户的Facebook帐户已经激活。用户不必输入登录信息,而是获得消息“您已经授权了thisApp”和“取消”和“确定”按钮。
注销按钮发生在TableViewController中。
更新1
即使实现了这些额外的方法,我的用户仍然登录到Facebook。我尝试了unLink方法,但这似乎并不是我想要的,因为在这样做之后,当我将用户重新登录时,用户的应用程序内数据就不再是他的了。
if (indexPath.row == 3) {
identifier = nil;
NSLog(@"pressed logout");
[PFUser logOut];
[[PFFacebookUtils session]closeAndClearTokenInformation];
[[PFFacebookUtils session]close];
[[FBSession activeSession]closeAndClearTokenInformation];
[[FBSession activeSession]close];
[FBSession setActiveSession:nil];
[self.navigationController popToRootViewControllerAnimated:YES];
}我要做些什么才能让用户真正从手机上登录到Facebook上,而不是仅仅从当前的应用程序中登录呢?
发布于 2014-06-13 05:06:26
嗨,不知道您使用的是哪个Facebook,但通常从Facebook注销时,您必须清除令牌信息并关闭会话,参考developers.facebook和下面的链接。
http://developers.facebook.com/docs/reference/ios/3.0/class/FBSession/
http://developers.facebook.com/docs/reference/ios/3.0/class/FBSession/#close
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession setActiveSession:nil];你亦可查核这两个与你的问题有关的问题:-
Facebook图形api注销不工作
Facebook iOS SDK 3.1.1 "closeAndClearTokenInformation“方法无效
希望它对你有帮助
https://stackoverflow.com/questions/24197674
复制相似问题