iOS10 配置ATS

iOS10 适配 App Transport Security (ATS)

1、首先我们需要确定,工程开启ATS后,各个iOS版本是否能正常运行。
iOS9.0及以上的iOS系统是默认开启ATS的,之前我们通常关闭ATS的做法如下
这里写图片描述
但是现在这个方法被苹果给禁用了。
如果设置 AllowArbitrary Loads 为 NO 之后,iOS9.0的系统出现连接不上服务器,那么有可能是服务器端没有配置 HTTPS(Hypertext Transfer Protocol over Secure Socket Layer)
我们需要使用 nscurl 工具,诊断ATS连接问题, Mac系统需要OS X v10.11及以上,可以在终端中输入一下内容:

/usr/bin/nscurl --ats-diagnostics https://apple.com

https://apple.com 替换为你项目中服务器的域名。

2、如果出现
NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9801)

nw_coretls_read_one_record tls_handshake_process: [-9801]
需要在plist文件里作如下配置

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <false/>
        <key>NSExceptionDomains</key>
        <dict>
            <key>"Your domain url"</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <string>YES</string>
                <key>NSExceptionMinimumTLSVersion</key>
                <string>TLSv1.0</string>
            </dict>
        </dict>
    </dict>

这里需要注意的是,“ Your domain url ” 这个URL可能是服务器端重定向的URL,也就是说你APP端发送一个请求,经过服务器端的重定向,返回的是另一个URL, 这个URL就是我们需要做配置排除ATS的。

关于NSExceptionDomains 主键格式
这里写图片描述

以下ATS 的key会触发App Store复审时需要你对于使用这些key的解释:

  • NSAllowsArbitraryLoads
  • NSAllowsArbitraryLoadsForMedia
  • NSAllowsArbitraryLoadsInWebContent
  • NSExceptionAllowsInsecureHTTPLoads
  • NSExceptionMinimumTLSVersion

一些作为合格解释的范例:

  • Must connect to a server managed by another entity that does not support secure connections
  • Must support connecting to devices that cannot be upgraded to use secure connections, and that must be accessed via public host names
  • Must provide embedded web content from a variety of sources, but cannot use a class supported by the NSAllowsArbitraryLoadsInWebContent key
  • App loads media content that is encrypted and that contains no personalized information

苹果关于适配ATS的官方文档

猜你喜欢

转载自blog.csdn.net/MickeyChen_/article/details/54601621
今日推荐