如何从Facebook注销

嗨,我已经从developer.Facebook.com下载了Facebook的最新sdk,我在我的代码中实现了sdk。 现在,当我第一次发布到Facebooklogin到Facebook,并成功login后发布到Facebook,之后,它不要求login,但我想要求再次login。 所以我写了下面的注销function,但它不适合我。 有人有什么主意吗? 请帮帮我。

NSLog(@"Logged out of facebook"); NSHTTPCookie *cookie; NSHTTPCookieStorage *storage = [NSHTTPCookieStorage sharedHTTPCookieStorage]; for (cookie in [storage cookies]) { NSString* domainName = [cookie domain]; NSRange domainRange = [domainName rangeOfString:@"facebook"]; if(domainRange.length > 0) { [storage deleteCookie:cookie]; } } 

从Facebook登出,你只需要做:

 [FBSession.activeSession closeAndClearTokenInformation]; 

编辑1 :这将closures内存中的会话。 如果login是通过Safari进行的,那么在Safari中,会话仍然是开放的,恐怕你没有任何关系。

要确认这一点,请尝试打开Safari应用程序(独立版),并在login后使用您的应用程序inputfacebook.com。 会议将仍然开放。

根据FaceBook开发者文档,我们应该使用下面的代码

  // get the app delegate so that we can access the session property AppDelegate *appDelegate = [[UIApplication sharedApplication]delegate]; // this button's job is to flip-flop the session from open to closed if ([FBSession activeSession].isOpen) { // if a user logs out explicitly, we delete any cached token information, and next // time they run the applicaiton they will be presented with log in UX again; most // users will simply close the app or switch away, without logging out; this will // cause the implicit cached-token login to occur on next launch of the application [[FBSession activeSession] closeAndClearTokenInformation]; }