iOS9—xcode7常見錯誤https問題解決 – iPhone手機開發 iPhone軟體開發教學課程

遇到的錯誤

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
然後添加類似如下的配置:

    NSAppTransportSecurity
    
        NSExceptionDomains
        
            qq.com
            
                NSIncludesSubdomains
                
            
            sina.com.cn
            
                NSIncludesSubdomains
                
            
           
   

根據自己需要的域名修改, NSIncludeSubdomains 顧名思義是包括子域的意思。

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *