如何将NSExceptionDomains添加到xcode版本7.0.1的plist?

我想使用Xcode版本7.0.1捆绑一个基于HTML的网站作为iPhone应用程序,一切工作正常,我唯一的问题是,当我在iPhone 4s上testing应用程序,它不会显示通过http访问的图像。 但是,我可以访问另一个提供https访问其图像的网站的图像。

有什么办法可以添加HTTP支持的捆绑?

更新

我添加了一个NSExceptionDomains到我的plist文件,但我仍然有同样的问题

 <?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> 

基于这个问题,我也尝试了以下

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

更新

我添加了这里提到的代码,但仍然有相同的问题。

更新

正如所build议的那样,我将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> 

首先,你的Info.plist有两个独立的NSAppTransportSecurity键值对。 你应该解决,所以只有一对。

你的问题没有说明你的图像加载的域名。 如果可以包含这些信息,那么给出具体答案会更容易。

例如,如果您的图像是从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> 

如果您事先不知道图像将从哪个域加载,那么您可以允许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> 

请注意,尽pipe在第二个示例中包含appanalytics.embarcadero.com在技​​术上是冗余的,但build议您为应用将访问的所有已知域指定ATS例外。

您可以阅读本教程,了解如何configurationApp Transport Security,或者您可以像以前一样允许所有内容,只需在info.plist中添加名为“NSAllowsArbitraryLoads”的布尔键“NSAppTransportSecurity”,值为“YES”即可。

您的密钥名称是NSExceptionAllowsInsecureHTTPLoads但应该是NSTemporaryExceptionAllowsInsecureHTTPLoads

另外,你是否尝试添加

 <key>NSExceptionRequiresForwardSecrecy</key> <false/> 

到ATS域名的关键?
一些领域需要它。