- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我目前正在开发一个 iOS 项目,该项目利用 AWS SDK 将大型媒体文件下载到设备。我正在使用 CloudFront
分发内容并且下载工作正常,但是我在为这些操作实现网络队列时遇到了问题。无论我尝试什么,所有文件都想一次下载。
我正在使用 AWSContent downloadWithDownloadType:
方法来启动和监控实际下载的进度。
我已经尝试使用 NSOperationQueue
并设置 setMaxConcurrentOperationCount
,所有代码块都会立即执行。 :(
我感觉它可能可以通过 AppDelegate
中的 AWSServiceConfiguration
进行配置,但是文档对于您可以将哪些变量传递给该对象非常模糊... http://docs.aws.amazon.com/AWSiOSSDK/latest/Classes/AWSServiceConfiguration.html
有没有人有这方面的经验?
TIA
最佳答案
您的问题很可能是您误解了异步操作的方法。
I have tried using an NSOperationQueue and setting setMaxConcurrentOperationCount, and all the code blocks execute at once. :(
如果没有看到实际的代码,很难说出什么是绝对错误的,但很可能与以下步骤有关:
NSOperationQueue
maxConcurrentOperationsCount
设置为 2
AWSContent downloadWithDownloadType:
关键在第3点里面。这个方 block 到底是做什么的?我的猜测是它在实际下载完成之前完成。所以如果你有这样的东西:
NSOperationQueue *queue = [NSOperationQueue new];
queue.maxConcurrentOperationsCount = 2;
for (AWSContent *content in contentArray) { // Assume you already do have this array
[queue addOperationWithBlock:^() {
[content downloadWithDownloadType:AWSContentDownloadTypeIfNotCached
pinOnCompletion:YES
progressBlock:nil
completionHandler:^(AWSContent *content, NSData *data, NSError *error) {
// do some stuff here on completion
}];
}];
}
您的 block 在下载完成之前退出,允许下一个 block 在队列中运行并开始进一步的下载。
你应该简单地在你的 block 中添加一些同步机制,让操作只在完成 block 上完成。说:
NSOperationQueue *queue = [NSOperationQueue new];
queue.maxConcurrentOperationsCount = 2;
for (AWSContent *content in contentArray) { // Assume you already do have this array
[queue addOperationWithBlock:^() {
dispatch_semaphore_t dsema = dispatch_semaphore_create(0);
[content downloadWithDownloadType:AWSContentDownloadTypeIfNotCached
pinOnCompletion:YES
progressBlock:nil
completionHandler:^(AWSContent *content, NSData *data, NSError *error) {
// do some stuff here on completion
// ...
dispatch_semaphore_signal(dsema); // it's important to call this function in both error and success cases of download to free the block from queue
}];
dispatch_semaphore_wait(dsema, DISPATCH_TIME_FOREVER); // or another dispatch_time if you want your custom timeout instead of AWS
}];
}
实际上你的答案是https://stackoverflow.com/a/4326754/2392973
您只需将大量此类 block 安排到您的操作队列中即可。
关于ios - AWS SDK - 为 CloudFront 下载实现网络队列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40054061/
我已经为我们的 Cloudfront 分配设置了一个备用域名,这样我们就可以从 oursite.com 提供服务。我们想禁用 ourdistid.cloudfront.net,这样我们的站点只能从一个
假设一个域名为 www.example.com 的网站托管在网站托管商(而非亚马逊)的 LAMP 服务器上。该域由 Route53 管理。 是否有可能以某种方式保留 LAMP 网络服务器上的所有设置并
我在使Cloudfront具有多个来源的工作时遇到麻烦。 我有两个起源: 起源1 小路: 默认 (*) 起源: Custom-example1.com/p 起源2 小路: ns/ 起源: Custom
TLDR:我们必须通过为来自 Lambda 函数的响应创建新的缓存行为来欺骗 CloudFront 307 重定向缓存。 你不会相信我们离实现这一目标有多近。我们在最后一步卡得太厉害了。 商业案例:
How do you set a default root object for subdirectories for a statically hosted website on Cloudfron
有人知道如何使使用友好 url 的自定义来源的根文档无效吗? 例如:example.com ? 通过 AWS Create Invalidation 对话框请求的正确对象路径是什么? 文档仅引用实际文
我正在使用带有自定义源的 CloudFront,并希望将来自 Web 应用程序的某些请求重定向到 CloudFront(客户端使用直接 URL,不能更改为基于 CloudFront 的 URL)。为了
我正在尝试在 AWS CloudFront 上上传公钥。我按如下方式生成 key ssh-keygen -t ecdsa -b 521 我也试过 ssh-keygen -b 4096 当我通过控制台上
我在 wordpress 重定向中的重定向导致域更改时遇到了一些问题。 例子:网站 - noncdn.somedomain.comCDN 网址 - www.domain.com 当我打开没有尾部斜杠的
在 CloudFront 行为设置中,“全部”是将所有请求 header 转发到源吗? Values That You Specify When You Create or Update a Dist
我们的应用程序中使用的图像是从 Amazon CloudFront 呈现的。 修改现有图像时,它不会立即反射(reflect)图像更改,因为 CloudFront 需要大约 24 小时才能更新。 作为
我想设置亚马逊云端,但是 Assets 需要在 http 和 https 上都可用。 我也想使用多个 cname。例如xyz0.cloudfront.netxyz1.cloudfront.netxyz
路径模式属性的文档并不完全详尽。 The pattern to which this cache behavior applies. For example, you can specify imag
我浏览了文档并进行了大量搜索。这些是我知道我可以使用 CloudFront 创建的签名 url 做的事情: 使用固定策略设置时间限制 监控该项目被查看的次数 我还可以为我的签名 URL 设置命中限制吗
cloudfront 是否支持 TLSv1.3 我没有看到任何文档说它在 cloudfront 和自定义来源之间支持?我强烈要求使用 TLSv1.3 最佳答案 CloudFront 现在支持 TLS
我最近才在阅读 Varnish Cache 的功能,以帮助优化我的 PHP 网站的性能。我读到了一个名为 Edge Side Includes 的功能,它似乎让我可以选择构建可以缓存在组件级别的 ht
我是部署静态站点的新手。搜索了大约一段时间的解决方案,根据我遇到的问题,我没有找到任何有用的信息。 宗旨 :我想在 CloudFront 上运行我生成的 Nuxt.js 静态站点。 问题 : 跑命令n
我正在使用 Amazon CloudFront 传送一些 HDS 文件。我有一个原始服务器,它检查 HTTP HEADER REFERER,如果不允许,它会阻止它。 问题是云前端正在删除引用 head
我正在使用 lambda@edge 通过 cloudfront 重定向我的网站。 我已将版本化 lambda arn 附加到我的云前端缓存行为及其所有 4 个事件。 当我访问我的云端端点时,它会显示
有没有办法让 Amazon CloudFront 失效(通过管理控制台),使所有匹配模式的文件失效?例如图像/*.png 语境 - 我在我的网站上为图像设置了缓存控制,但错误地在 Apache 的缓存
我是一名优秀的程序员,十分优秀!