iPad 设备锁定时下载大文件需要 10 分钟以上
我有一个要求,用户可以依次下载多个文件。 当我的应用程序进入后台或 iPad 被锁定时,下载或网络服务响应只能持续 10 分钟。
我的下载发生在一个单独的线程中,经过一些谷歌搜索和 stackoverflow 链接后,我实现了 beginBackgroundTaskWithExpirationHandler:
。
和 iOS 文档
现在我选择的一些文件已下载有些失败是因为后台任务最多只能运行 10 分钟。
有什么替代方案吗? 当应用程序进入后台时我应该完全暂停下载吗? 有人可以帮我解决这个问题吗?
如果我的下载正在进行中,我已经成功地做到了这一点,即不结束后台任务
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{ NSLog(@"\n beginBackgroundTaskWithExpirationHandler 称为\n"); if(![self checkIfDownloadInProgress]){ [自我结束任务完成]; } }];
仅当用户手动锁定设备时,此功能才有效。如果设备在 2 分钟后自动锁定,应用程序运行 10 分钟,然后崩溃 有人可以帮忙吗?
I have a requirement where user can download multiple files one after other.
When my app goes in background OR when iPad is locked, the download or web-service response can be get only for 10 minutes.
My download happens in a separate thread, I have implemented beginBackgroundTaskWithExpirationHandler:
after some googling and on stackoverflow links.
How to implement Task completion
App crash because of auto lock in iphone?
and iOS documetation
Now some of my selected files are downloaded and some failed because one can run background task only for 10 min max.
Is there any alternative for this??
Should I pause download completely while app goes in background??
Can anyone help me regarding this??
I have succeeded to do so by not ending background task if my download is in progress
bgTask = [app beginBackgroundTaskWithExpirationHandler:^{
NSLog(@"\n beginBackgroundTaskWithExpirationHandler called \n");
if(![self checkIfDownloadInProgress]){
[self endTaskOnCompletion];
}
}];
This works only if device is manually locked by user. If device locks automatically after 2 min, app runs for 10 min and then it is crashed
Can anybody help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我发现这是可能的唯一方法:
本文档总结了网络和多任务处理中可能的解决方案:
https://developer.apple.com/library/ios/#technotes /tn2277/_index.html
Only way I found this is possible:
This document pretty much summarizes possible solutions in Networking And Multitasking:
https://developer.apple.com/library/ios/#technotes/tn2277/_index.html