iOS9—xcode7常见错误https问题解决

遇到的错误

The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.

少年莫慌,这是升级的ios9的https问题,解决起来很简单,关闭他,咱仍是用httpios

解决

1:在Info.plist中添加NSAppTransportSecurity类型Dictionary。
2:在NSAppTransportSecurity下添加NSAllowsArbitraryLoads类型Boolean,值设为YES
3:注意,单元测试下面也有一个Info.plist,修改那个文件是没有做用的!markdown

其余

若是想让有的域名支持https的话也能够这么配置:
补充了配置的方法
对于实在不支持HTTPS的应该首先考虑添加例外dom

添加例外的方式也很简单:
左键Info.plist选择open with source code
而后添加相似以下的配置:单元测试

<key>NSAppTransportSecurity</key>
    <dict>
        <key>NSExceptionDomains</key>
        <dict>
            <key>qq.com</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
            <key>sina.com.cn</key>
            <dict>
                <key>NSIncludesSubdomains</key>
                <true/>
            </dict>
           </dict>
   </dict>

根据本身须要的域名修改, NSIncludeSubdomains 顾名思义是包括子域的意思。测试

相关文章
相关标签/搜索