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 顧名思義是包括子域的意思。測試

相關文章
相關標籤/搜索