stringWithContentsOfURL cookie jar in El Capitan

I have a small open source application.
I used [NSString stringWithContentsOfURL] to download website’s html and check if user has been logged in in Safari.

Before El Capitan everything was working fine: stringWithContentsOfURL used sharedCookiesStorage (Safari ones) and returned the html of the page as logged in user.

  • NSTableView with custom cells
  • How do I increase the height of the title bar in a Cocoa application?
  • NSTask Launch causing crash
  • Mac - Get Battery/Charging Status (Plugged in or not)
  • What replacement for UITableViewAutomaticDimension should I use to get the same effect in NSTableView?
  • NSObject subclass in Swift: hash vs hashValue, isEqual vs ==
  • But in El Capitan this is not working this way: stringWithContentsOfURL returns the html of the page, where the user is not logged in. So it doesn’t use Safari’s cookies anymore. (I’m logged in on this page in Safari).

    There were some changes in El Capitan, I had to add all my domains to NSExceptionDomains in info.plist, so it could get data from http://, but I haven’t found any changes in stringWithContentsOfURL in the latest OSX release.

    What can be the problem? Everything was fine before upgrading. Maybe I could somehow pass [NSHTTPCookieStorage sharedHTTPCookieStorage] to [NSString stringWithContentsOfURL]?

    The actual code, that gets html is:

    html = [NSString stringWithContentsOfURL:[NSURL URLWithString: [trackerSettDict objectForKey:@"loginCheckURL"]] encoding: NSUTF8StringEncoding error:&error];

    Some code to test the error:

    NSError *error;
    NSString *html;
    html = [NSString stringWithContentsOfURL:[NSURL URLWithString: @""] encoding: NSWindowsCP1251StringEncoding error:&error];
    NSLog(@"%@", html);

    Solutions Collect From Internet About “stringWithContentsOfURL cookie jar in El Capitan”

    In El Capitan, each app has its own cookie storage. You can access Safari’s cookie storage by [NSHTTPCookieStorage sharedCookieStorageForGroupContainerIdentifier:"Cookies"].