1

在我的应用程序中,我正在使用 Facebook。我将 FB 与我的应用程序集成在一起。登录也正确发生。但是,当我尝试注销时,它在fbDidLogout中显示注销成功,但是当我们再次尝试登录时,这意味着它只是显示登录页面并使用先前输入的用户名和密码进行登录。

我们如何才能正确注销。

任何人都可以提供帮助或建议

这是我的代码

这是登录注销按钮操作

- (IBAction)LoginOrLogout 
{
// If the user is not connected (logged in) then connect.  Otherwise logout.
if (!isConnected)
{

    // Set the permissions.
    // Without specifying permissions the access to Facebook is imposibble.
    permissions = [[NSArray arrayWithObjects:@"read_stream", @"publish_stream", nil] retain];

    // Set the Facebook object we declared. We’ll use the declared object from the application
    // delegate.
    facebook = [[Facebook alloc] initWithAppId:@"329082513817407" andDelegate:self];



    [btnPublish setHidden:NO];
    [messageTextField setHidden:NO];

    [facebook authorize:permissions];

    // Change the lblUser label's message.
    [lblUser setText:@"Please wait..."];

    isConnected = YES;
     [self setLoginButtonImage];
}
else 
{
    [facebook logout:self];
    [messageTextField setHidden:YES];

    [lblUser setText:@"Tap on the Login to connect to Facebook"];
    isConnected = NO;
    [self setLoginButtonImage];
}
}

这些是其他方法

-(void)fbDidLogin
{
// Save the access token key info.
[self saveAccessTokenKeyInfo];

// Get the user's info.
[facebook requestWithGraphPath:@"me" andDelegate:self];
}

 -(void)fbDidNotLogin:(BOOL)cancelled
{
UIAlertView *al = [[UIAlertView alloc] initWithTitle:@"Tonify" message:@"Login cancelled." delegate:self cancelButtonTitle:nil otherButtonTitles:@"OK", nil];
[al show];
[self LoginOrLogout];
}

-(void)fbDidLogout
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSLog(@"defaults fbDidLogout  ........%@",defaults);
if ([defaults objectForKey:@"FBAccessTokenKey"]) 
{
    [defaults removeObjectForKey:@"FBAccessTokenKey"];
    [defaults removeObjectForKey:@"FBExpirationDateKey"];
    [defaults synchronize];
}
NSLog(@"defaults fbDidLogout ........%@",defaults);
NSLog(@"logout success!");

// Keep this for testing purposes.
NSLog(@"Logged out Succes");

// Hide the publish button.
[btnPublish setHidden:YES];
}
4

2 回答 2

2

使用此方法:

-(void)fbDidLogout
{
  NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
  NSLog(@"defaults fbDidLogout  ........%@",defaults);
  if ([defaults objectForKey:@"FBAccessTokenKey"]) 
  {
      [defaults removeObjectForKey:@"FBAccessTokenKey"];
      [defaults removeObjectForKey:@"FBExpirationDateKey"];
      [defaults synchronize];
  }

  // Hide the publish button.
  [btnPublish setHidden:YES];

   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];
     }
   }
 }
于 2012-06-03T13:42:00.520 回答
0

保险箱的答案是正确的,那么您也可以在他的方法中添加这一行代码。

[facebook invalidateSession];

如果您要使用它,这仅适用于 FB 的 gragh api。

于 2012-06-04T07:26:25.317 回答