【问题标题】:Using pinned certificates with AVPlayer in iOS在 iOS 中使用带有 AVPlayer 的固定证书
【发布时间】:2021-02-06 20:58:50
【问题描述】:

有没有办法让 AVPlayer 在 iOS 中强制执行证书固定?

我们的视频加载代码基本上是:

let url = URL(string: "https://www.example.com/file.mp4")!
let item = AVPlayerItem(url: url)

我们可以使用此委托方法通过 URLSession 进行证书固定:https://developer.apple.com/documentation/foundation/urlsessiondelegate/1409308-urlsession。但是我还没有为 AVPlayer 找到类似的方法,如果有的话。

感谢您的帮助!

【问题讨论】:

    标签: ios swift avplayer certificate-pinning


    【解决方案1】:

    实现的相关方法应该是AVAssetResourceLoaderDelegate(docs)中的这个:

    optional func resourceLoader(_ resourceLoader: AVAssetResourceLoader, 
         shouldWaitForResponseTo authenticationChallenge: URLAuthenticationChallenge) -> Bool
    

    在您的情况下,直接创建一个AVURLAsset,并在其资源加载器上设置您的委托实现。然后使用资产初始化播放器项目。

    let url = URL(string: "https://www.example.com/file.mp4")!
    let urlAsset = AVURLAsset(url: url)
    urlAsset.resourceLoader.setDelegate(resourceLoaderDelegate,
                                        queue: .main)
    let item = AVPlayerItem(asset: urlAsset)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-07
      • 1970-01-01
      • 2013-03-21
      • 2020-06-01
      • 2016-04-09
      • 2019-04-28
      相关资源
      最近更新 更多