我正在使用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选项卡上打开并显示最后一个用户&# 39; 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,而不是仅仅从应用程序上的当前会话?
答案 0 :(得分:1)
您不知道您正在使用哪个Facebook sdk,但通常从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"方法没有工作
希望它可以帮助你
答案 1 :(得分:0)
在您退出之前尝试取消用户对象与Facebook的链接。
[PFFacebookUtils unlinkUserInBackground:[PFUser currentUser] block:^(BOOL Success,NSError *unlinkError){
if(!unlinkError){
// User unlinked
}else{
// Erro while unlink user
}
}];
答案 2 :(得分:0)
您的应用可以选择使用Facebook进行登录,并仅控制您应用的登录/退出。
如果需要,可以通过代理登录他们的Facebook帐户,但是您无法将其登录到Facebook,因为这会影响使用Facebook的所有其他应用程序。
如果用户想要退出Facebook,他们可以使用Facebook应用程序,也可以在设备的“设置”中进行操作。