嗨,我已经从developer.Facebook.com下载了最新的Facebook sdk,我在我的代码中实现了sdk。现在,当我第一次登录Facebook登录Facebook时,登录到Facebook后,它会发布到Facebook,之后它不会要求登录,但我想要求再次登录。所以我写了下面的注销功能,但它对我没用。有谁有想法吗?请帮帮我。
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];
}
}
答案 0 :(得分:2)
要从Facebook退出,您只需要这样做:
[FBSession.activeSession closeAndClearTokenInformation];
编辑1 :这将关闭内存中会话。如果登录是通过Safari进行的,那么在Safari中会话仍处于打开状态,我担心你与此无关。
要确认这一点,请尝试打开Safari应用程序(独立)并在使用您的应用程序登录后输入facebook.com。会议仍将开放。
答案 1 :(得分:0)
根据FaceBook Developer Documentation,我们应该使用以下代码
// 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];
}