我得到了ATS错误:App Transport Security阻止了一个明文http(http://)资源加载,因为它不安全.可以通过应用程序的Info.pList文件配置临时例外.
我无法理解原因.我的baseURL是https格式
struct NetworkManager { let baseURL = "https://swAPI.co/API/" let session = URLSession(configuration: .default) func fetchEndpoint(endpoint: Endpoint,completion: @escaPing (_ response: Result) -> VoID) { self.fetchURL(url: baseURL + endpoint.URL(),completion: completion) } func fetchURL(url: String,completion: @escaPing (_ response: Result) -> VoID) { let url = URL(string: url)! let request = URLRequest(url: url) let task = session.dataTask(with: request) { data,response,error in if error != nil { completion(.Failure(error)) } else { if let data = data { if let Json = try? JsONSerialization.JsonObject(with: data,options: []) { OperationQueue.main.addOperation({ switch Json { case let objectResponse as JsONArray: completion(.Success(objectResponse as AnyObject?)) case let objectResponse as JsONDict: completion(.Success(objectResponse as AnyObject?)) default: break } }) } } } } task.resume() }}
请给我并提示!!
我只是一个新手,我猜测SWAPI只支持http协议.
为了支持不安全的连接,请执行以下 *** 作:
>打开info.pList文件
>将名为App Transport Security Settings的密钥添加为Dictionary(Dictionary应为默认类型)
>将名为Allow Arbitrary Loads的子项添加为布尔值(布尔值应为默认类型).将其设置为YES
另见屏幕截图:
总结以上是内存溢出为你收集整理的iOS swift:App Transport Security阻止了一个明文HTTP(http://)资源全部内容,希望文章能够帮你解决iOS swift:App Transport Security阻止了一个明文HTTP(http://)资源所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)