Safari扩展程序上的App Transport Security [英] App Transport Security on Safari Extension
问题描述
我的App扩展程序需要打开许多网站的URL.我的操作如下:
My App extension need to open URL from many websites. I do as following:
for (NSExtensionItem *item in self.extensionContext.inputItems) {
for (NSItemProvider *itemProvider in item.attachments) {
if ([itemProvider hasItemConformingToTypeIdentifier:(NSString *)kUTTypeURL]) {
[itemProvider loadItemForTypeIdentifier:(NSString *)kUTTypeURL options:nil completionHandler:^(NSURL *url, NSError *error) {
NSLog(@"URL: %@",url);
我可以获取URL,但是此时我遇到了以下错误:
I can get the URL, but at this point I got this error:
由于应用传输安全性不安全,因此它阻止了明文HTTP(http://)资源加载.可以通过您应用的Info.plist文件配置临时例外.
App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
我试图完全关闭ATS,
I tried to completely turn off ATS,
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key> <true/>
</dict>
但是它不起作用,并且我无法在NSExceptionDomain内列出网站.我在模拟器和设备上尝试过.有人可以帮忙吗?
but it doesn't work, and I cannot list websites inside NSExceptionDomain. I tried on simulator and on device. Somebody could help?
编辑
我认为导致问题的代码是这样的:
i think that the code that cause the issue it's this:
NSString* htmlString = [NSString stringWithContentsOfURL: url encoding:NSUTF8StringEncoding]
我在url记录后使用这一行代码来将html作为纯文本获取.
I use this line of code after url log to get the html as plain text.
推荐答案
您是将NSAppTransportSecurity
字典添加到应用扩展的 Info.plist 文件中,还是添加到父应用的 Info.plist 文件?因为如果扩展程序正在发出请求,则该异常需要位于扩展程序的 Info.plist 文件中.
Are you adding the NSAppTransportSecurity
dictionary to the app extension's Info.plist file, or just in the parent app's Info.plist file? Because if the extension is making the requests, the exception needs to be in the extension's Info.plist file.
如果这没有帮助,请尝试直接使用NSURLConnection
并查看是否有任何区别.我怀疑会不会,但是值得一试.
If that doesn't help, try using NSURLConnection
directly and see if it makes any difference. I doubt it will, but it might be worth a try.
这篇关于Safari扩展程序上的App Transport Security的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!