sin*_*ibu 2 security xcode ios swift5
我无法在 swift 5、XCode 版本 11.6 (11E708) 和 iOS 13.6 中发布到服务器。我收到此错误:
2020-08-26 08:20:55.252545-0400 iris[1642:721953] Task <BBB3809B-7BEF-4F60-9685-774027ADA7E6>.<1> finished with error [-1022] 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={NSUnderlyingError=0x2810ad710 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://localhost:8000/searchImage/, NSErrorFailingURLKey=http://localhost:8000/searchImage/, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}
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={NSUnderlyingError=0x2810ad710 {Error Domain=kCFErrorDomainCFNetwork Code=-1022 "(null)"}, NSErrorFailingURLStringKey=http://localhost:8000/searchImage/, NSErrorFailingURLKey=http://localhost:8000/searchImage/, NSLocalizedDescription=The resource could not be loaded because the App Transport Security policy requires the use of a secure connection.}
Run Code Online (Sandbox Code Playgroud)
我关注了这个问题How can I delete obliged data in Xcode 8? 并更新了我的 info.plist
<key> App Transport Security Settings </key>
<dict>
<key> Allow Arbitrary Loads </key>
<true />
Run Code Online (Sandbox Code Playgroud)
请注意,此时我不关心安全性。此外,我尝试了干净的构建,然后删除了我的派生数据文件夹,但仍然无法发布到服务器。在另一个项目中,我在 Info.plist 中设置了这个键,一切都很好。有什么建议么?
如果您info.plist从源代码进行编辑,要允许所有域,请更改以下值:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
Run Code Online (Sandbox Code Playgroud)
那么它应该如下所示作为属性列表:
为了更好的方法,您可以默认禁用它并为特定域添加例外,如下所示。
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<false/>
<key>NSExceptionDomains</key>
<dict>
<key>yourdomain.com</key>
<dict>
<key>NSExceptionAllowsInsecureHTTPLoads</key>
<true/>
<key>NSIncludesSubdomains</key>
<true/>
</dict>
</dict>
</dict>
Run Code Online (Sandbox Code Playgroud)