Solution to Facebook ios sdk failure to log out of the bug

Source: Internet
Author: User

Let's talk about how to jump to safari in the Facebook ios sdk and log on to the app.

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

In the facbook. M file, just comment out the above section. My versions are from lines 241 to 260.


Next, let's talk about the cause of logout failure. First, let's look at the method called during logout:

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

At this time we found that he just destroyed the cookie under the http://login.facebook.com, so our account sometimes can not log out normally, because he did not destroy the cookie under the https://login.facebook.com !, Therefore, we need to add the following code in invalidatesession:

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

For the sake of simplicity, I added 1. Do not name it like this!


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.