我需要在加载AVURLAsset
时,从AVAssetResourceLoaderDelegate
的resourceLoader(:shouldWaitForLoadingOfRequestedResource:)
中向媒体加载请求添加一个自定义header。
AVAssetResourceLoadingRequest
的request
是一个不可变的属性,因此不可能在其上调用addValue(...)
。
在redirect
上有一个AVAssetResourceLoadingRequest
请求属性,理论上它可以用作原始请求加上必要的标头,但是它似乎没有任何效果(也就是说,发出的请求没有自定义标头)。
编辑:正如我所怀疑的,resourceLoader(:shouldWaitForLoadingOfRequestedResource:)
回调是在发送loadingRequest.request
之后调用的。
编辑2:所以AVURLAsset
确实有AVURLAssetHTTPCookiesKey
选项键,它允许一个人添加自定义cookies,而不是任意的headers。
发布于 2017-03-06 04:15:02
在resourceLoader(:shouldWaitForLoadingOfRequestedResource:)
方法的实现中,应该有如下代码:
// somehow create the URLRequest that you need with the correct headers
let redirectRequest: URLRequest
loadingRequest.redirect = redirectRequest
loadingRequest.finishLoading
// tell the resource loader that you know how it should handle the request
return true
这是一种奇怪的界面,文档可能更清晰,但我认为这基本上是您所需要的。
https://stackoverflow.com/questions/42416246
复制相似问题