1

我正在使用 FBConnct 实现 Facebook 集成,它工作正常,但是当我想从 Facebook 注销时它不起作用。

我的代码如下:

- (IBAction)logOutbuttonPressed:(id)sender { 
        [Facebook logout:self];
        }
        - (void)fbDidLogout {


            NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
            [defaults removeObjectForKey:@"FBAccessTokenKey"];
            [defaults removeObjectForKey:@"FBExpirationDateKey"];
            NSLog(@" after %@",facebook.accessToken);
            NSLog(@" date%@",facebook.expirationDate);
            [defaults synchronize];
          }


        - (void)logout:(id<FBSessionDelegate>)delegate {
          [self logout];

          if (delegate != self.sessionDelegate &&
            [delegate respondsToSelector:@selector(fbDidLogout)]) {
            [delegate fbDidLogout];
          }
4

3 回答 3

3
+(void)fbDidLogout
{
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];

    if ([defaults objectForKey:@"FBAccessTokenKey"]) 
    {
        [defaults removeObjectForKey:@"FBAccessTokenKey"];
        [defaults removeObjectForKey:@"FBExpirationDateKey"];
        [defaults synchronize];
    }

    // Hide the publish button.

    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-23T07:07:55.270 回答
1

您还需要为 facebook 注销实现此代码

   - (void)fbDidLogout {


        NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
        [defaults removeObjectForKey:@"FBAccessTokenKey"];
        [defaults removeObjectForKey:@"FBExpirationDateKey"];
        NSLog(@" after %@",facebook.accessToken);
        NSLog(@" date%@",facebook.expirationDate);
        [defaults synchronize];

    //        Finding the Facebook Cookies and deleting them
    NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];
    NSArray* facebookCookies = [cookies cookiesForURL:
                                [NSURL URLWithString:@"http://login.facebook.com"]];
    for (NSHTTPCookie* cookie in facebookCookies) {
        [cookies deleteCookie:cookie];
    }
    fbGraph = nil;
      }

在您的第二个视图控制器中尝试此导入“FBConnect.h”

然后 .......

FBSession *session = [FBSession session]; [session logout];
于 2012-06-23T07:03:20.140 回答
1

调用此方法从 facebook 注销。

    - (void)logOutFB {

    fbGraph.accessToken = nil;
    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-23T08:55:38.057 回答