El Capitan 中的 stringWithContentsOfURL cookie 罐
stringWithContentsOfURL cookie jar in El Capitan
我有一个小型开源应用程序。
我使用 [NSString stringWithContentsOfURL]
下载网站的 html 并检查用户是否已在 Safari 中登录。
在 El Capitan 之前一切正常:stringWithContentsOfURL
使用 sharedCookiesStorage(Safari 的)并以登录用户身份返回页面的 html。
但在 El Capitan 中,这不是这样工作的:stringWithContentsOfURL
returns 页面的 html,用户未登录。因此它不使用Safari 的 cookies 了。 (我在 Safari 中登录了此页面)。
El Capitan 有一些变化,我必须将我所有的域添加到 info.plist
中的 NSExceptionDomains
,这样它才能从 http:// 获取数据,但我没有找到最新 OSX 版本中 stringWithContentsOfURL
的任何更改。
可能是什么问题?升级前一切正常。也许我可以通过某种方式将 [NSHTTPCookieStorage sharedHTTPCookieStorage]
传递给 [NSString stringWithContentsOfURL]
?
获得html的实际代码是:
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 存储
我有一个小型开源应用程序。
我使用 [NSString stringWithContentsOfURL]
下载网站的 html 并检查用户是否已在 Safari 中登录。
在 El Capitan 之前一切正常:stringWithContentsOfURL
使用 sharedCookiesStorage(Safari 的)并以登录用户身份返回页面的 html。
但在 El Capitan 中,这不是这样工作的:stringWithContentsOfURL
returns 页面的 html,用户未登录。因此它不使用Safari 的 cookies 了。 (我在 Safari 中登录了此页面)。
El Capitan 有一些变化,我必须将我所有的域添加到 info.plist
中的 NSExceptionDomains
,这样它才能从 http:// 获取数据,但我没有找到最新 OSX 版本中 stringWithContentsOfURL
的任何更改。
可能是什么问题?升级前一切正常。也许我可以通过某种方式将 [NSHTTPCookieStorage sharedHTTPCookieStorage]
传递给 [NSString stringWithContentsOfURL]
?
获得html的实际代码是:
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"]
.