Xcode中http 请求失败对应的错误提示如下:
2019-03-18 14:56:32.687068+0800 Afinia Debug[10987:469562] App Transport Security has blocked a cleartext HTTP (http://) resource load since it is insecure. Temporary exceptions can be configured via your app's Info.plist file.
2019-03-18 14:56:32.687124+0800 Afinia Debug[10987:469562] Cannot start load of Task <6EE5455B-6B4E-4452-A4EA-2DD76EA8DBB9>.<1> since it does not conform to ATS policy
2019-03-18 14:56:32.687268+0800 Afinia Debug[10987:469628] Task <6EE5455B-6B4E-4452-A4EA-2DD76EA8DBB9>.<1> finished with error - code: -1022
2019-03-18 14:56:32.689733+0800 Afinia Debug[10987:469524] Task <6EE5455B-6B4E-4452-A4EA-2DD76EA8DBB9>.<1> load failed with error Error Domain=NSURLErrorDomain Code=-1022 "The resource could not be loaded because the App Transport Security policy requires the use of a secure connection." UserInfo={NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection., NSErrorFailingURLStringKey=http://afinia.s3-website-us-west-1.amazonaws.com/AfiniaV250.LKD, NSErrorFailingURLKey=http://afinia.s3-website-us-west-1.amazonaws.com/AfiniaV250.LKD, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDownloadTask <6EE5455B-6B4E-4452-A4EA-2DD76EA8DBB9>.<1>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask <6EE5455B-6B4E-4452-A4EA-2DD76EA8DBB9>.<1>, NSUnderlyingError=0x600000f54180 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}} [-1022]
[!]error ===> TT_ERROR_CONFIG_READ_VALUE_KEY[root:Global key:ModelColor] (ReadConfigValue)
那么如何设置呢?
首先需要在 info.plist 文件中选择 App Transport Security Settings 添加 Allow Arbitrary Loads和Allow Arbitrary Loads in Web Content 设置为YES
其次需要注意的是,必须缇娜家Exception Domains,设置内容如上图所示。
切:NSExceptionMinimumTLSVersion 必须必设置为TLSv1.0 否则 错误仍然存在。
PS: 注意单词的拼写。