【问题标题】:ios 9 and NSAppTransportSecurityios 9 和 NSAppTransportSecurity
【发布时间】:2015-09-19 01:18:23
【问题描述】:

iOS 9 存在问题,请与服务器配合使用。 我的 info.plist 设置:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

当您通过 Xcode 运行应用程序时,一切都很好。与服务器的工作完美进行。但是一旦我停止应用程序并尝试通过简单地单击模拟器中的图标来运行它。网络停止工作。当我将应用程序发送到 TestFlight 中的 Review 时,同样的问题。应用程序已安装,但网络再次停止工作。

Xcode 7.0 (7a220) iOS 9.0

【问题讨论】:

    标签: ios objective-c xcode ios9 xcode7


    【解决方案1】:

    你确定它不起作用吗?我测试了它,一切都很好。

    可能的行动

    启用调试模式,构建您的应用程序,从 Xcode 运行它并确保您不会收到 App Transport Security 错误:

    App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure.

    使用模拟器从 Xcode 启动它时。现在找到同一个模拟器的DEVICE_CODE

    (Hint: it will be one of these ~/Library/Developer/CoreSimulator/Devices/. The easiest way to find this code from Xcode is to go Window-&gt;Devices)

    并使用控制台打开其日志文件:

    ~/Library/Logs/CoreSimulator/<DEVICE_CODE>/system.log
    

    清除历史记录(以防万一您可以再次从 Xcode 启动您的应用并确保您的输出进入您打开的日志文件,并且您仍然没有获得 App Transport Security em> 里面有错误)。

    现在从模拟器启动您的应用,并检查日志中是否有任何与 App Transport Security 相关的错误。

    对我来说,在使用 Xcode 工作时,如果没有,我也没有。

    ===================================

    附言

    强烈建议不要将 NSAllowsArbitraryLoads 设置为 true,您宁愿通过以下方式获得所需的结果:

    <key>NSAppTransportSecurity</key>
    <dict>
      <key>NSExceptionDomains</key>
      <dict>
        <key>yourserver.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>
    

    【讨论】:

    • 感谢您的回答,但第一个选项(可能的操作:)无济于事。日志文件中没有任何错误没有出现,一切正常。但是在停止应用程序后,Xcode 网络不再工作。什么触动 NSExceptionDomains 这个方法也会导致同样的问题。
    • 你有理由确定问题的原因是 NSAppTransportSecurity 吗?您说控制台中没有错误。
    • 如果您的 Mac 运行 10.11,您可以使用新的 nscurl 命令和 --ats-diagnostics option。这将查看您正在连接的服务,并告诉您需要调整哪些设置才能连接,同时尽可能保持屏蔽。
    • 我不明白可能是什么原因。现在我的服务器也可以使用 https 和 TLC v1.2 请求,但也不要将其传递给 iOS 9。iOS 8 一切都很好。
    • 嗯。已知 NSAppTransportSecurity 会导致 HTTP 请求出现问题。对于 HTTPS 它不应该阻止任何东西。也许为您的问题添加更多标签(例如,有 nsurlrequestafnetworking)并尝试搜索@macshome 建议的问题 是有意义的
    【解决方案2】:

    应该这样做,你需要在你的Plist中添加以下记录 Apple Documentation

    它很懒,所以你的框架可以访问互联网

    NSAppTransportSecurity

    NSAllowsArbitraryLoads

    【讨论】:

      【解决方案3】:

      非常简单,只需按照以下步骤即可:

      1. 应用传输安全设置。
      2. 允许任意加载。
      3. 异常域和域/主机引用。

      注意:出现此问题是因为您的项目设置默认不允许任何跨站点脚本引用。因此,它会阻止任何超出您的应用程序的服务调用。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-12-18
        • 2015-10-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-01-18
        • 2015-12-16
        • 2018-10-24
        相关资源
        最近更新 更多