Reset Facebook Token Reference - Facebook SDK 4.0

 ̄綄美尐妖づ 提交于 2019-11-30 06:59:37

问题


I previously used the following to clear and reset the Facebook access token

[FBSession.activeSession closeAndClearTokenInformation];

Since the update to 4.0 this no longer works. FBSession.activeSession has changed to [FBSDKAccessToken currentAccessToken].

I however can't find the latest version of closeAndClearTokenInformation that works with the latest version. Any suggestions?


回答1:


FBSDKLoginManager *logMeOut = [[FBSDKLoginManager alloc] init];
[logMeOut logOut];

or

[FBSDKAccessToken setCurrentAccessToken:nil];
[FBSDKProfile setCurrentProfile:nil];

to logout

Then when you login again, make sure to set:

login.loginBehavior = FBSDKLoginBehaviorWeb;

Like so:

FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
login.loginBehavior = FBSDKLoginBehaviorWeb;
[login logInWithReadPermissions:@[@"user_friends"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
         etc...
}];

I found some info in the docs saying FBSDKLoginBehaviorWeb can be used for "kiosk" apps; which I guess are apps designed to have more than one person log into them routinely.

One thing to note, this login method creates a modal UIWebView which is set up for portrait mode. I'm not sure if its possible to change this yet.




回答2:


Swift 2+ Simple Solution

FBSDKLoginManager().logOut()

Swift 5+ Simple Solution

LoginManager().logOut()



回答3:


In swift you may want to do the following for close the session entirely:

import FacebookCore
import FacebookLogin

//...

//in your method:

let fbLoginManager = LoginManager()
fbLoginManager.logOut()
AccessToken.current = nil
UserProfile.current = nil


来源:https://stackoverflow.com/questions/29421659/reset-facebook-token-reference-facebook-sdk-4-0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!