如何關閉會話Facebook-iOS-Sdk
每當我啓動我的應用程序或殺死應用程序後,它會給我以前的登錄會話詳細信息。當我點擊facebook按鈕。我已經使用了所有的東西[appDelegate.session closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession.activeSession closeAndClearTokenInformation]
..但活動會話仍然沒有關閉..如何關閉點擊前的會話數據。關閉Facebook會話在Facebook-Ios-Sdk
我使用下面的代碼來清除,但每當我點擊Facebook按鈕開始新的會話..它讓我回到以前的憑據。
- (IBAction)buttonClickHandler:(id)sender {
appDelegate = [[UIApplication sharedApplication]delegate];
// this button's job is to flip-flop the session from open to closed
if (appDelegate.session.isOpen) {
[appDelegate.session closeAndClearTokenInformation];
[FBSession.activeSession close];
[FBSession.activeSession closeAndClearTokenInformation];
FBSession.activeSession=nil;
} else {
if (appDelegate.session.state != FBSessionStateCreated) {
// Create a new, logged out session.
appDelegate.session = [[FBSession alloc] init];
}
// if the session isn't open, let's open it now and present the login UX to the user
[FBSession.activeSession closeAndClearTokenInformation];
FBSession.activeSession=nil;
[FBSession.activeSession openWithBehavior:FBSessionLoginBehaviorForcingWebView
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
// and here we make sure to update our UX according to the new session state
NSLog(@" state=%d",state);
[FBRequestConnection
startForMeWithCompletionHandler:^(FBRequestConnection *connection,
id<FBGraphUser> user,
NSError *error) {
userInfo = @"";
// Example: typed access (name)
// - no special permissions required
userInfo = user.username;
NSLog(@"string %@", userInfo);
[self checkfacebook];
}];
}]; }
}
和viewDidLoad中
- (void)viewDidLoad
{
[super viewDidLoad];
AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate];
if (!appDelegate.session.isOpen) {
// create a fresh session object
appDelegate.session = [[FBSession alloc] init];
if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
// even though we had a cached token, we need to login to make the session usable
[FBSession.activeSession close];
FBSession.activeSession=nil;
}
}
NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"http://login.facebook.com"]];
for (NSHTTPCookie* cookie in facebookCookies) {
[cookies deleteCookie:cookie];
}
}
你好謝謝你!我已經嘗試了所有的事情,但這個奇怪的事情一次又一次地發生:(...... – Christien
這確實很奇怪與fb api。我有同樣的「問題」。順便說一句,當你從facebook應用程序註銷(實際fb應用程序你的設備),那麼你真的註銷了,如果你只註銷你的應用程序(而不是fb的),你將用sso登錄你在fb應用程序中使用的帳戶... – Yanchi
太棒了!謝謝!上面的工作完全適合我。 – Anthony