【问题标题】:Alamofire - Use of undeclared type 'ServerTrustPolicy'?Alamofire - 使用未声明的类型“ServerTrustPolicy”?
【发布时间】:2019-11-22 08:06:52
【问题描述】:

Github 上的官方 Alamofire 文档建议使用以下内容来禁用对 url 的评估。

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

但是,我收到了错误:

Use of undeclared type 'ServerTrustPolicy'

(是的,我已经导入了 Alamofire)

Alamofire 改变了这一点吗?

【问题讨论】:

    标签: swift alamofire nsurlsession


    【解决方案1】:

    是的,Alamofire 似乎已经改变了这一点,所以文档似乎已经过时了:

    之前的 ServerTrustPolicy 枚举已被重构为实现 ServerTrustEvaluating 的类

    参考: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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-01
      相关资源
      最近更新 更多