1

我在我的应用程序中使用 facebook sdk。我用facebook简单地登录了,如下所示:

FBLoginView *loginview = [[FBLoginView alloc] initWithPermissions:[NSArray arrayWithObject:@"publish_actions"]];

UIImage *loginImage = [UIImage imageNamed:@"login_facebook_button.png"];

// loginview.backgroundColor = [UIColor redColor];
loginview.frame = CGRectMake(15, 294, loginImage.size.width, loginImage.size.height);

for (id obj in loginview.subviews)
{
    if ([obj isKindOfClass:[UIButton class]])
    {
        UIButton * loginButton =  obj;

        [loginButton setBackgroundImage:loginImage forState:UIControlStateNormal];
        [loginButton setBackgroundImage:nil forState:UIControlStateSelected];
        [loginButton setBackgroundImage:nil forState:UIControlStateHighlighted];
        [loginButton sizeToFit];
    }
    if ([obj isKindOfClass:[UILabel class]])
    {
        UILabel * loginLabel =  obj;
        loginLabel.text = [Lang get:@"SIGN_IN_WITH_FACEBOOK"];
        loginLabel.textAlignment = UITextAlignmentCenter;
        [loginLabel setTextColor:[UIColor colorWithRed:228.0/255.0 green:228.0/255.0 blue:228.0/255.0 alpha:1.0]];
        [loginLabel setShadowColor:[UIColor colorWithRed:127.0/255.0 green:127.0/255.0 blue:127.0/255.0 alpha:1.0]];
        loginLabel.frame = CGRectMake(0, 0, loginImage.size.width, loginImage.size.height);
    }
}

loginview.delegate = self;

[self.view addSubview:loginview];

我已经正常登录了。但是当我尝试使用它注销时

[FBSession.activeSession closeAndClearTokenInformation];

我得到了异常,它没有写出真正的错误。此时我的应用程序崩溃了。

但是它实际上清除了令牌,因为崩溃后它已经注销。

那么我做错了什么?

谢谢

4

2 回答 2

12
FBSession* session = [FBSession activeSession];
[session closeAndClearTokenInformation];
[session close];
[FBSession setActiveSession:nil];

NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
NSArray* facebookCookies = [cookies cookiesForURL:[NSURL         URLWithString:@"https://facebook.com/"]];

for (NSHTTPCookie* cookie in facebookCookies) {
    [cookies deleteCookie:cookie];
}
于 2014-06-17T11:20:26.620 回答
0

用这个:

 - (void)logout:(id<FBSessionDelegate>)delegate {

  self.sessionDelegate = delegate;
  [_accessToken release];
  _accessToken = nil;
  [_expirationDate release];
  _expirationDate = nil;

  NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
  NSArray* facebookCookies = [cookies cookiesForURL:[NSURL URLWithString:@"http://login.facebook.com"]];

  for (NSHTTPCookie* cookie in facebookCookies) {
    [cookies deleteCookie:cookie];
  }

  if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogout)]) {
    [_sessionDelegate fbDidLogout];
  }
}

请参阅ios-facebook-connect-logout-not-deleting-login-details链接。

于 2012-09-19T06:43:17.627 回答