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

来源:互联网 发布:php连接数据库 编辑:程序博客网 时间:2024/06/12 20:41

遇到的错误

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

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

解决

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

其他

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

添加例外的方式也很简单:
左键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 顾名思义是包括子域的意思。

0 0
原创粉丝点击