gpt4 book ai didi

swift - 允许任意加载在 Swift 5 转换后不起作用

转载 作者:行者123 更新时间:2023-11-30 10:42:43 24 4
gpt4 key购买 nike

我有一个应用程序,它使用自签名证书与本地托管服务器上的 API 进行交互。我已经在 info.plist 中包含了允许任意加载的代码,并且还包含了当我们收到挑战时的 URLSessionDelegate。

我在 urlsession 函数中有一个打印行,并且该行永远不会被打印,所以我觉得该代码永远不会被调用。我在我的类中继承 URLSessionDelegate。这一切在 Swift 4 中都有效。

func urlSession(_ session: URLSession, didReceive challenge: URLAuthenticationChallenge, completionHandler: @escaping (URLSession.AuthChallengeDisposition, URLCredential?) -> Void) {

//accept all certs when testing, perform default handling otherwise
print("Accepting cert as always")
completionHandler(.useCredential, URLCredential(trust: challenge.protectionSpace.serverTrust!))
}

这是收到的错误:

2019-06-04 09:59:55.604023-0500 The MUT[8866:1617557] NSURLSession/NSURLConnection HTTP load failed (kCFStreamErrorDomainSSL, -9843)
2019-06-04 09:59:55.604056-0500 The MUT[8866:1617557] Task <F8D75C99-49ED-45BE-B764-942B748942DB>.<1> HTTP load failed (error code: -1202 [3:-9843])
2019-06-04 09:59:55.604150-0500 The MUT[8866:1617558] Task <F8D75C99-49ED-45BE-B764-942B748942DB>.<1> finished with error - code: -1202```

最佳答案

确保您已正确签署委托(delegate),或尝试在 ViewController 的 viewDidLoad 中对其进行签名。

这个错误:HTTP Load Failed 的解决方法如下:

NSAppTransportSecurity -> NSAllowsArbitraryLoads = true

关于swift - 允许任意加载在 Swift 5 转换后不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56446552/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com