stringWithContentsOfURL在El Capitan的cookie jar [英] stringWithContentsOfURL cookie jar in El Capitan

查看:145
本文介绍了stringWithContentsOfURL在El Capitan的cookie jar的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个小的开源应用程序。
我使用 [NSString stringWithContentsOfURL] 下载网站的html并检查用户是否已在Safari中登录。

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.

在El Capitan之前一切正常: stringWithContentsOfURL 使用sharedCookiesStorage(Safari),并返回用户登录的页面的html。

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

但在El Capitan中,这不是这样工作的: stringWithContentsOfURL 返回页面的html,用户没有登录。不再使用Safari的cookie了。 (我在Safari中在此页面上登录。)

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).

El Capitan有一些变化,我必须将所有域添加到 NSExceptionDomains info.plist ,所以它可以从http://获取数据,但我没有发现任何变化 stringWithContentsOfURL 在最新的OSX版本中。

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.

可能有什么问题?一切都很好,升级。也许我可以通过 [NSHTTPCookieStorage sharedHTTPCookieStorage] [NSString stringWithContentsOfURL]

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

获取html的实际代码是:

The actual code, that gets html is:

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

测试错误的一些代码:

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


推荐答案

在El Capitan中,每个应用程序都有自己的Cookie存储。您可以通过 [NSHTTPCookieStorage sharedCookieStorageForGroupContainerIdentifier:Cookies] 访问Safari的Cookie存储空间。

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

这篇关于stringWithContentsOfURL在El Capitan的cookie jar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆