Download large files which takes more than 10 min when iPad device is locked

早过忘川 提交于 2019-12-10 17:36: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

https://developer.apple.com/library/ios/#documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html

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?


回答1:


  1. If it is not necessary then pause it. It is the best thing that you can do.
  2. Else when your expiration handler is called then you can start again background task and you will get 10 mins more.



回答2:


Only way I found this is possible:

  1. Use resumable transfers, download/upload in chunks.
  2. When application is sent to background continue transfer for 10 minutes
  3. Cleanup when time is up
  4. 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



来源:https://stackoverflow.com/questions/9411122/download-large-files-which-takes-more-than-10-min-when-ipad-device-is-locked

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!