首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在AVAssetResourceLoaderDelegate加载请求中添加自定义headers

如何在AVAssetResourceLoaderDelegate加载请求中添加自定义headers
EN

Stack Overflow用户
提问于 2017-02-23 12:50:08
回答 1查看 1.3K关注 0票数 3

我需要在加载AVURLAsset时,从AVAssetResourceLoaderDelegateresourceLoader(:shouldWaitForLoadingOfRequestedResource:)中向媒体加载请求添加一个自定义header。

AVAssetResourceLoadingRequestrequest是一个不可变的属性,因此不可能在其上调用addValue(...)

redirect上有一个AVAssetResourceLoadingRequest请求属性,理论上它可以用作原始请求加上必要的标头,但是它似乎没有任何效果(也就是说,发出的请求没有自定义标头)。

编辑:正如我所怀疑的,resourceLoader(:shouldWaitForLoadingOfRequestedResource:)回调是在发送loadingRequest.request之后调用的。

编辑2:所以AVURLAsset确实有AVURLAssetHTTPCookiesKey选项键,它允许一个人添加自定义cookies,而不是任意的headers。

EN

回答 1

Stack Overflow用户

发布于 2017-03-06 04:15:02

resourceLoader(:shouldWaitForLoadingOfRequestedResource:)方法的实现中,应该有如下代码:

代码语言:javascript
运行
复制
// 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

这是一种奇怪的界面,文档可能更清晰,但我认为这基本上是您所需要的。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42416246

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档