[英]When a user logs out of my iOS app, the next time they try to login with Facebook, they should have to re-enter their login credentials
I'm building an iOS app with Parse and Facebook frameworks. 我正在使用Parse和Facebook框架构建iOS应用。
I log the user in 我登录用户
-(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];
}
}];
}
No problem logging users in or out. 登录或注销用户都没有问题。 But when I do log the user out and pop to the root view controller (the one with the "login with facebook" button), if I click that button, Facebook opens on a Safari tab with the last user's Facebook account already active.
但是,当我注销用户并弹出到根视图控制器(带有“使用Facebook登录”按钮的按钮)时,如果单击该按钮,Facebook将在Safari选项卡上打开,而最后一个用户的Facebook帐户已处于活动状态。 Instead of having to enter login information, the user gets the message "You have already authorized thisApp " and a "cancel" and "ok" button.
用户不必输入登录信息,而获得消息“您已授权thisApp ”以及“取消”和“确定”按钮。
The logout button is occurring from within a TableViewController. 注销按钮是在TableViewController内部发生的。
[UPDATE 1] [更新1]
Even after implementing these additional methods, my user is still logged into Facebook. 即使实现了这些其他方法,我的用户仍然可以登录Facebook。 I tried the unLink method but that doesn't seem to be what I'm after, because after doing that, when I log a user back in, that user's in-app data no longer is attributed to him.
我尝试了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];
}
What do I have to do to actually log the user out of Facebook from the phone itself, as opposed to just from this current session on the app? 我要怎么做才能从手机本身实际注销用户,而不是直接从应用程序当前会话中注销该用户?
hi don't know which Facebook sdk you are using but normally for logout from Facebook you have to clear token information and close session refer developers.facebook and following links. 嗨,您不知道您使用的是哪个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/
http://developers.facebook.com/docs/reference/ios/3.0/class/FBSession/#close http://developers.facebook.com/docs/reference/ios/3.0/class/FBSession/#close
[FBSession.activeSession closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession setActiveSession:nil];
you can also check this two question related your issue :- 您还可以检查与您的问题有关的这两个问题:
Facebook graph api log out not working Facebook图形API注销无法正常工作
Facebook iOS SDK 3.1.1 "closeAndClearTokenInformation" method no working Facebook iOS SDK 3.1.1“ closeAndClearTokenInformation”方法无效
hope its helps you 希望它可以帮助您
Try unlinking the user object from Facebook before you logout. 注销之前,请尝试从Facebook取消链接用户对象。
[PFFacebookUtils unlinkUserInBackground:[PFUser currentUser] block:^(BOOL Success,NSError *unlinkError){
if(!unlinkError){
// User unlinked
}else{
// Erro while unlink user
}
}];
Your app can choose to use Facebook for login, and control login/logout on your app only. 您的应用程序可以选择使用Facebook进行登录,并仅在您的应用程序上控制登录/注销。
The login to their Facebook account is done by proxy if needed, but you can't log them out of Facebook, as that would impact all other apps using Facebook. 如果需要,可以通过代理登录他们的Facebook帐户,但是您不能将他们注销到Facebook,因为这会影响所有其他使用Facebook的应用程序。
If the user wants to log out of Facebook they either use the Facebook app or do it in the Settings on their device. 如果用户要注销Facebook,则可以使用Facebook应用程序,也可以在设备的“设置”中进行操作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.