ATS相关

2016-12-23  本文已影响67人  DoKeer
原本苹果定于2017.01.01后苹果审核将要限制HTTP请求,需要广大开发者提前做好准备。现在又说要延后了。

To give you additional time to prepare, this deadline has been extended and we will provide another update when a new deadline is confirmed


NSAppTransportSecurity (Dictionary - iOS, macOS) Use this key to describe your app’s intended HTTP connection behavior if you require exceptions from best security practices or you want to enable new security features.

The NSAppTransportSecurity key is supported in iOS 9.0 and later and in OS X v10.11 and later, and is available in both apps and app extensions.

//检测服务器支持的TSL版本 v1.2
> /usr/bin/nscurl --ats-diagnostics https://apple.com

这里分为三种情况

    <key>NSAppTransportSecurity</key>
    <dict>
        <key>NSAllowsArbitraryLoads</key>
        <false/>
    </dict>
<key>NSAppTransportSecurity</key>
<dict>
    <key>NSExceptionDomains</key>
    <dict>
         <key>tcv.ielpm.cn</key>
         <dict>
             <key>NSExceptionAllowsInsecureHTTPLoads</key>
             <true/>
             <key>NSIncludesSubdomains</key>
             <true/>
         </dict>
    </dict>
    <key>NSAllowsArbitraryLoads</key>
    <false/>
</dict>

(If you add this key to your Info.plist file, then, irrespective of the value of the key, ATS ignores the value of the NSAllowsArbitraryLoads key.)

还有一个问题,这个key是支持iOS 10以后,那要适配老板本怎么办?文档给出的方法是同时设置

NSAllowsArbitraryLoads = YES和
NSAllowsArbitraryLoadsInWebContent = YES

(To support older versions of iOS and macOS, you can employ this key and still manually configure ATS. To do so, set this key’s value to YES and also configure the NSAllowsArbitraryLoads subkeys.)

很多公司测试环境都是HTTP请求,生产环境才是HTTPS。开发时这样设置

//单独设置
NSAllowsArbitraryLoads = YES //可以访问。
//设置两个 
NSAllowsArbitraryLoads = YES && NSAllowsArbitraryLoadsInWebContent = YES //webView之外的无法访问

怎么解决这个问题?我现在没有好办法,只能发包之前再改。希望大神们指点迷津!


注:详细请参考文档
https://developer.apple.com/library/content/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW59

上一篇 下一篇

猜你喜欢

热点阅读