2015-10-06 51 views
11

我想使用Xcode版本7.0.1将基于HTML的网站捆绑为iPhone应用程序,一切正常,我唯一的问题是,当我在iPhone 4上测试应用程序时,它不会显示通过http访问的图像。但是,我可以访问另一个网站的图像,该网站提供对其图像的访问权限https如何将NSExceptionDomains添加到xcode版本7.0.1的plist?

有什么办法可以将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> 

我也试过以下基于此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> 

更新

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

更新

至于建议,我改变了对的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> 
+0

请访问:https://nabla-c0d3.github.io/blog/2015/06/16/ios9-security-privacy/ –

回答

10

首先,您的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访问:虽然appanalytics.embarcadero.com在第二个例子中包括在技术上是多余的,建议您指定ATS例外所有已知域次

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

注在你的应用程序将访问。

+0

谢谢,我知道图像的域名,并补充说,如你所建议的,但没有帮助,我更新了这个问题。 – Jack

+0

看着你上次更新的plist,你从字面上理解了我的例子,因为你已经在NSExceptionDomains中为'myproject.com.ca'包含了两个不同的条目。每个域只能有一个条目,但该域需要有例外。 – adurdin

1

您可以阅读本教程,了解如何配置App Transport Security,或者您可以像以前一样允许所有内容,方法是在info.plist中添加名为“NSAllowsArbitraryLoads”的布尔键“NSAppTransportSecurity”。

1

你的键名是NSExceptionAllowsInsecureHTTPLoads但它应该是NSTemporaryExceptionAllowsInsecureHTTPLoads

而且,你有没有尝试

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

添加到ATS域的关键?
某些域需要它。