Github上的官方Alamofire文档建议使用以下方法禁用url的求值。

let serverTrustPolicies: [String: ServerTrustPolicy] = [
    "blahblah.com": .disableEvaluation
]

但是,我发现了一个错误:
Use of undeclared type 'ServerTrustPolicy'

(是的,我进口了阿拉莫菲尔)
阿拉莫菲公司是否已经废弃或改变了这一点?

最佳答案

是的,Alamofire似乎已经改变了这一点,因此文档似乎已经过时:
以前的ServerTrustPolicy枚举已重构为实现servertrustevaluation的类
参考:https://github.com/Alamofire/Alamofire/pull/2344
您的解决方案将取决于您使用的是哪个版本的Alamofire。当然,在4.6.0或更低版本中,这不会对您造成影响,因此您似乎使用的是较新的版本。
在最新的master分支(代表5.0.0-beta7发行版)中,似乎您正在寻找的等效代码是evaluators property on ServerTrustManager,您可以使用提供的DefaultTrustEvaluator class for the ServerTrustEvaluating objects。如果需要高级使用,同一文件中还有其他几个求值器。
相关源文件:https://github.com/Alamofire/Alamofire/blob/master/Source/ServerTrustEvaluation.swift

关于swift - Alamofire-使用未声明类型的“ServerTrustPolicy”吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/57008942/

10-13 06:55