问题描述
我有一个要求,用户可以一个接一个地下载多个文件。
当我的应用程序进入后台,当iPad被锁定时,下载或Web服务响应只能获得10分钟。
我的下载发生在一个单独的线程,我已经实现了 beginBackgroundTaskWithExpirationHandler:
经过一些谷歌搜索和stackoverflow链接。
和iOS documetation
现在我的一些选定文件被下载,一些失败,因为最后只能运行10分钟的后台任务。
有没有替代这个?
应用程序在背景中应该完全暂停下载吗?
任何人都可以帮助我吗?
如果我的下载正在进行,我没有结束后台任务,所以我已经成功了。
$ b
bgTask = [app beginBackgroundTaskWithExpirationHandler:^ {
NSLog(@\ beginBackgroundTaskWithExpirationHandler叫做\\\
);
if(![self checkIfDownloadInProgress]){
[self endTaskOnCompletion];
}
}];
只有在用户手动锁定设备时才有效。如果设备在2分钟后自动锁定,应用程序运行10分钟,然后崩溃
可以帮助吗?
只有这样,我才发现这是可能的:
- 使用可恢复的传输,以块形式下载/上传
- 当应用程序发送到后台继续传输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 crashedCan anybody help?
Only way I found this is possible:
- Use resumable transfers, download/upload in chunks.
- When application is sent to background continue transfer for 10 minutes
- Cleanup when time is up
- Resume transfer when application is activated
This document pretty much summarizes possible solutions in Networking And Multitasking:https://developer.apple.com/library/ios/#technotes/tn2277/_index.html
这篇关于下载大型文件时,iPad设备被锁定超过10分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!