iOS9與XCode7中不能使用http連接的快速解決辦法
在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文件可以繼續(xù)使用http連接,具體的方法如下:
1.在項目左側(cè)找到Info.plist文件,可以通過Filter來搜索
2.在右側(cè)點擊Add Row添加NSAppTransportSecurity,類型為Dictionary,然后再添加子項目NSAllowsArbitraryLoads類行為Boolean值為YES
這樣就可以重新使用普通的http連接了。不過有條件的話,還是去搞一個https吧.
以上所述是小編給大家介紹的iOS9與XCode7中不能使用http連接的快速解決辦法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
- iOS 9無法訪問HTTP的解決方法
- iOS中使用NSURLConnection處理HTTP同步與異步請求
- iOS的HTTP請求和請求回執(zhí)類用法小結(jié)
- iOS應(yīng)用開發(fā)中AFNetworking庫的常用HTTP操作方法小結(jié)
- HTTP/2 協(xié)議用于 iOS 推送提醒服務(wù) (APNS)
- 判斷iOS應(yīng)用是否開放HTTP權(quán)限的方法
- iOS通過http post上傳圖片
- iOS應(yīng)用中發(fā)送HTTP的get請求以及HTTP異步請求的方法
- iOS9蘋果將原h(huán)ttp協(xié)議改成了https協(xié)議的方法
- IOS10.11 無法訪問http的問題解決辦法
相關(guān)文章
iOS 使用Moya網(wǎng)絡(luò)請求的實現(xiàn)方法
這篇文章主要介紹了iOS 使用Moya網(wǎng)絡(luò)請求的實現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-07-07IOS UIImagePickerController從拍照、圖庫、相冊獲取圖片
這篇文章主要介紹了IOS UIImagePickerController從拍照、圖庫、相冊獲取圖片的相關(guān)資料,希望通過本文能幫助到大家,需要的朋友可以參考下2017-09-09