【问题标题】:How to logout from facebook如何从脸书注销
【发布时间】:2014-05-20 10:07:56
【问题描述】:

您好,我已经从 developer.Facebook.com 下载了 Facebook 的最新 sdk,并在我的代码中实现了该 sdk。现在,当我第一次发布到 Facebook 时,它会去 Safari 登录 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];
        }
}

【问题讨论】:

    标签: ios iphone facebook


    【解决方案1】:

    要退出 Facebook,您只需:

    [FBSession.activeSession closeAndClearTokenInformation];
    

    EDIT 1:这将关闭 in-memory 会话。如果登录是通过 Safari 进行的,那么它是在会话仍然打开的 Safari 中,恐怕你与此无关。

    要确认这一点,请在使用您的应用程序登录后尝试打开 Safari 应用程序(独立)并输入 facebook.com。会议仍将开放。

    【讨论】:

      【解决方案2】:

      根据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];
      }
      

      【讨论】:

        猜你喜欢
        • 2011-05-20
        • 1970-01-01
        • 1970-01-01
        • 2011-08-08
        • 1970-01-01
        • 2013-01-17
        相关资源
        最近更新 更多