iPhone: Facebook logout feature does not working

你离开我真会死。 提交于 2019-12-02 14:05:04

问题


I am implementing Facebook integration using FBConnct and it works fine but when I want to log out from the Facebook it doesn't work.

My code is as follows:

- (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];
          }

回答1:


+(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];
        }
    }
}



回答2:


You need to implement this code for facebook logout as well

   - (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;
      }

Try this import 'FBConnect.h' in ur second view controller

then .......

FBSession *session = [FBSession session]; [session logout];



回答3:


Call this method to logout from 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];
        }
    }
    }


来源:https://stackoverflow.com/questions/11167593/iphone-facebook-logout-feature-does-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!