stringWithContentsOfURL cookie jar in El Capitan

坚强是说给别人听的谎言 提交于 2019-12-10 11:34:20

问题


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.

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: @"https://google.com"] encoding: NSWindowsCP1251StringEncoding error:&error];
NSLog(@"%@", html);

回答1:


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



来源:https://stackoverflow.com/questions/32921572/stringwithcontentsofurl-cookie-jar-in-el-capitan

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