facebook ios sdk 無法登出bug的解決方案

來源:互聯網
上載者:User

先說下facebook ios sdk中如何不跳到safari而在程式內登陸

//  UIDevice *device = [UIDevice currentDevice];//  if ([device respondsToSelector:@selector(isMultitaskingSupported)] && [device isMultitaskingSupported]) {//    if (tryFBAppAuth) {//      NSString *scheme = kFBAppAuthURLScheme;//      if (_urlSchemeSuffix) {//        scheme = [scheme stringByAppendingString:@"2"];//      }//      NSString *urlPrefix = [NSString stringWithFormat:@"%@://%@", scheme, kFBAppAuthURLPath];//      NSString *fbAppUrl = [FBRequest serializeURL:urlPrefix params:params];//      didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];//    }////    if (trySafariAuth && !didOpenOtherApp) {//      NSString *nextUrl = [self getOwnBaseUrl];//      [params setValue:nextUrl forKey:@"redirect_uri"];////      NSString *fbAppUrl = [FBRequest serializeURL:loginDialogURL params:params];//      didOpenOtherApp = [[UIApplication sharedApplication] openURL:[NSURL URLWithString:fbAppUrl]];//    }//  }

在Facbook.m檔案中,注釋掉上面那段即可,我的版本是241到260行


然後說下無法登出的原因,先看下登出時調用的方法:

- (void)logout {    [self invalidateSession];            if ([self.sessionDelegate respondsToSelector:@selector(fbDidLogout)]) {        [self.sessionDelegate fbDidLogout];    }}

- (void)invalidateSession {    self.accessToken = nil;    self.expirationDate = nil;        NSHTTPCookieStorage* cookies = [NSHTTPCookieStorage sharedHTTPCookieStorage];    NSArray* facebookCookies = [cookies cookiesForURL:                                [NSURL URLWithString:@"http://login.facebook.com"]];        for (NSHTTPCookie* cookie in facebookCookies) {        [cookies deleteCookie:cookie];    }}

這時候我們發現他只是銷毀掉了http://login.facebook.com下的cookie,所以我們的帳號有時會無法正常登出,因為他沒銷毀https://login.facebook.com下的cookie!,所以我們需要在invalidateSession中加入如下代碼:

NSArray* facebookCookies1 = [cookies cookiesForURL:                                [NSURL URLWithString:@"https://login.facebook.com"]];        for (NSHTTPCookie* cookie in facebookCookies1) {        [cookies deleteCookie:cookie];    }

簡單起見我就加了個1,大家起名不要這樣啊!


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.