I would like to bundle a HTML based website as an iPhone app using Xcode Version 7.0.1, everything works fine and my only issue is that when I test the application on iPhone 4s, it wont show images that are accessed through http
. However, I could access images of another website that provide https
access to its images.
我想使用Xcode Version 7.0.1将基于HTML的网站捆绑为iPhone应用程序,一切正常,我唯一的问题是,当我在iPhone 4s上测试应用程序时,它不会显示通过http访问的图像。但是,我可以访问另一个提供https访问其图像的网站的图像。
Is there any way to add http support to the bundle?
有没有办法为捆绑添加http支持?
Update
I added an NSExceptionDomains
to my plist file, but I still have the same issue
我在我的plist文件中添加了一个NSExceptionDomains,但我仍然有同样的问题
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>My Project</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIcons</key>
<dict/>
<key>CFBundleIcons~ipad</key>
<dict/>
<key>CFBundleIdentifier</key>
<string>com.myproject.names</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>1.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0.1</string>
<key>CFBundleSignature</key>
<string>myproject</string>
<key>CFBundleVersion</key>
<string>1.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>UIMainStoryboardFile</key>
<string>Main_iPhone</string>
<key>UIMainStoryboardFile~ipad</key>
<string>Main_iPad</string>
<key>UIRequiresFullScreen</key>
<string>YES</string>
<key>UIStatusBarHidden</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>appanalytics.embarcadero.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key><true/>
</dict>
</dict>
</dict>
</dict>
</plist>
I also tried following based on this question
我也试过基于这个问题
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>mydomain.com</key>
<dict>
<!--Include to allow subdomains-->
<key>NSIncludesSubdomains</key>
<true/>
<!--Include to allow HTTP requests-->
<key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
<true/>
<!--Include to specify minimum TLS version-->
<key>NSTemporaryExceptionMinimumTLSVersion</key>
<string>TLSv1.1</string>
</dict>
</dict>
</dict>
Update
I added the code mentioned in here but still have the same issue.
我添加了这里提到的代码,但仍然有相同的问题。
Update
As suggested, I changed the plist to following but still has the same issue. Also, I added http:// to values of key tags to no avail.
正如所建议的,我将plist更改为以下但仍有相同的问题。另外,我将http://添加到关键标签的值中无济于事。
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleDisplayName</key>
<string>My Project</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIcons</key>
<dict/>
<key>CFBundleIcons~ipad</key>
<dict/>
<key>CFBundleIdentifier</key>
<string>com.myproject.names</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>1.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>3.1.6</string>
<key>CFBundleSignature</key>
<string>myproject</string>
<key>CFBundleVersion</key>
<string>1.2</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIMainStoryboardFile</key>
<string>Main_iPhone</string>
<key>UIMainStoryboardFile~ipad</key>
<string>Main_iPad</string>
<key>UIRequiresFullScreen</key>
<string>YES</string>
<key>UIStatusBarHidden</key>
<false/>
<key>UIStatusBarStyle</key>
<string>UIStatusBarStyleLightContent</string>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
<key>UIViewControllerBasedStatusBarAppearance</key>
<false/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>myproject.com.ca</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
<key>myproject.com.ca</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
</dict>
</plist>
3 个解决方案
#1
12
Firstly, your Info.plist has two separate NSAppTransportSecurity key-value pairs. You should fix that so there is only the one pair.
首先,您的Info.plist有两个单独的NSAppTransportSecurity键值对。你应该修复它,所以只有一对。
Your question doesn’t say what domains your images are loaded from. It would be easier to give a specific answer if you could include this information.
您的问题没有说明您的图片是从哪个域加载的。如果您可以包含此信息,则更容易给出具体答案。
If, for example, your images are loaded from example.com
or subdomains, you could add an exception as follows:
例如,如果您的图像是从example.com或子域加载的,则可以添加例外,如下所示:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>appanalytics.embarcadero.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
<key>example.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
If you don’t know in advance what domains the images will be loaded from, then you can instead allows HTTP access to all domains:
如果您事先不知道将从哪些域加载图像,那么您可以允许对所有域进行HTTP访问:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>appanalytics.embarcadero.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
Note that although the inclusion of appanalytics.embarcadero.com
in this second example is technically redundant, it is recommended that you specify ATS exceptions for all known domains that your app will access.
请注意,尽管在第二个示例中包含appanalytics.embarcadero.com在技术上是多余的,但建议您为应用将访问的所有已知域指定ATS例外。
#2
1
You can read this tutorial on how to configure App Transport Security or you could just allow everything as before by adding Dictionary "NSAppTransportSecurity" with a Boolean key named "NSAllowsArbitraryLoads" with the value "YES" in your info.plist.
您可以阅读本教程,了解如何配置App Transport Security,或者您可以像以前一样通过在info.plist中添加名为“NSAllowsArbitraryLoads”且值为“YES”的布尔键“NSAppTransportSecurity”来允许所有内容。
#3
1
Your key name is NSExceptionAllowsInsecureHTTPLoads
but it should be NSTemporaryExceptionAllowsInsecureHTTPLoads
您的密钥名称是NSExceptionAllowsInsecureHTTPLoads但它应该是NSTemporaryExceptionAllowsInsecureHTTPLoads
Also, did you try to add
另外,你是否尝试添加
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
to ATS domain's key?
Some domains requires it.
到ATS域的关键?有些域需要它。
#1
12
Firstly, your Info.plist has two separate NSAppTransportSecurity key-value pairs. You should fix that so there is only the one pair.
首先,您的Info.plist有两个单独的NSAppTransportSecurity键值对。你应该修复它,所以只有一对。
Your question doesn’t say what domains your images are loaded from. It would be easier to give a specific answer if you could include this information.
您的问题没有说明您的图片是从哪个域加载的。如果您可以包含此信息,则更容易给出具体答案。
If, for example, your images are loaded from example.com
or subdomains, you could add an exception as follows:
例如,如果您的图像是从example.com或子域加载的,则可以添加例外,如下所示:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSExceptionDomains</key>
<dict>
<key>appanalytics.embarcadero.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
<key>example.com</key>
<dict>
<key>NSIncludesSubdomains</key>
<true/>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
If you don’t know in advance what domains the images will be loaded from, then you can instead allows HTTP access to all domains:
如果您事先不知道将从哪些域加载图像,那么您可以允许对所有域进行HTTP访问:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
<key>NSExceptionDomains</key>
<dict>
<key>appanalytics.embarcadero.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
</dict>
</dict>
</dict>
Note that although the inclusion of appanalytics.embarcadero.com
in this second example is technically redundant, it is recommended that you specify ATS exceptions for all known domains that your app will access.
请注意,尽管在第二个示例中包含appanalytics.embarcadero.com在技术上是多余的,但建议您为应用将访问的所有已知域指定ATS例外。
#2
1
You can read this tutorial on how to configure App Transport Security or you could just allow everything as before by adding Dictionary "NSAppTransportSecurity" with a Boolean key named "NSAllowsArbitraryLoads" with the value "YES" in your info.plist.
您可以阅读本教程,了解如何配置App Transport Security,或者您可以像以前一样通过在info.plist中添加名为“NSAllowsArbitraryLoads”且值为“YES”的布尔键“NSAppTransportSecurity”来允许所有内容。
#3
1
Your key name is NSExceptionAllowsInsecureHTTPLoads
but it should be NSTemporaryExceptionAllowsInsecureHTTPLoads
您的密钥名称是NSExceptionAllowsInsecureHTTPLoads但它应该是NSTemporaryExceptionAllowsInsecureHTTPLoads
Also, did you try to add
另外,你是否尝试添加
<key>NSExceptionRequiresForwardSecrecy</key>
<false/>
to ATS domain's key?
Some domains requires it.
到ATS域的关键?有些域需要它。