在Xcode7.0及以上版本中編譯iOS APP時,默認會使用iOS9的一項新特性,使得所有http連接被禁用,項目裡使用的API沒有https支持,就悲劇了。差了官方文檔,有這麼一段話
App Transport Security App Transport Security (ATS) enforces best practices in the secure connections between an app and its back end. ATS prevents accidental disclosure, provides secure default behavior, and is easy to adopt; it is also on by default in iOS 9 and OS X v10.11. You should adopt ATS as soon as possible, regardless of whether you're creating a new app or updating an existing one. If you're developing a new app, you should use HTTPS exclusively. If you have an existing app, you should use HTTPS as much as you can right now, and create a plan for migrating the rest of your app as soon as possible. In addition, your communication through higher-level APIs needs to be encrypted using TLS version 1.2 with forward secrecy. If you try to make a connection that doesn't follow this requirement, an error is thrown. If your app needs to make a request to an insecure domain, you have to specify this domain in your app's Info.plist file.
在這裡面可以看到,通過修改Info.plist文件可以繼續使用http連接,具體的方法如下:
1.在項目左側找到Info.plist文件,可以通過Filter來搜索
2.在右側點擊Add Row添加NSAppTransportSecurity,類型為Dictionary,然後再添加子項目NSAllowsArbitraryLoads類行為Boolean值為YES
這樣就可以重新使用普通的http連接了。不過有條件的話,還是去搞一個https吧.
以上所述是小編給大家介紹的iOS9與XCode7中不能使用http連接的快速解決辦法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對本站網站的支持!