0

i am trying download load the large videos(400 mb) into background cont.... until end of the video in iOS-7 using Xcode-5 . But After 10 or 5 min downloading is stop .

i wrote the code like below and i set the "background fetch mode is YES". Is There any wrong with my code.

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

Ref 2: enter image description here

Question : How can i kept alive the my URL request upto my videos are downloaded in background mode?

Thanks in Advence.

- (void)applicationDidEnterBackground:(UIApplication *)application
{
    UIApplication *app = [UIApplication sharedApplication];
    UIBackgroundTaskIdentifier m_backgroundTaskId;
     m_backgroundTaskId = [[UIApplication sharedApplication]
                          beginBackgroundTaskWithExpirationHandler:^(void) {
                              m_isWentBackground = YES;
                              [m_dataController saveUnfineshedDownoadsToFile];
                              [[UIApplication sharedApplication]
                               endBackgroundTask:m_backgroundTaskId];
                              m_backgroundTaskId = UIBackgroundTaskInvalid;
                          }];

 }
Nag_iphone
  • 967
  • 7
  • 22

3 Answers3

2

You are doing it wrong, the beginBackgroundTaskWithExpirationHandler will give you up to 10 extra minutes to download, but if you want real background download, you have to look into Background Transfer Service

You have 2 tutorials:

jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
1

The beginBackgroundTaskWithExpirationHandler of UIApplication is supposed to be used a "task finisher". There is nothing wrong with your code, but it is the purpose of this code that is the problem. This operation will be kept alive for a maximum of 10 min or so, and it is the operating system which decides for how long the task will be operational. If you are downloading a 400mb video, it is not what you need. You should consider another way to do this task - Which is not in a background operation. A background operation, by Apple own definition can not last more than 10 minutes.

Perhaps, performing queued background operations, that will gradually append data, until you will have the complete video? Or doing this operation while app is not in background in another thread?

A 400mb video does not sounds like something a mobile device should do, as default.

Raz
  • 2,633
  • 1
  • 24
  • 44
  • "another way to do this task", means plz give me some explanation its help for me. How can i kept alive the my URL request upto my videos are downloaded in background mode – Nag_iphone Feb 12 '14 at 07:30
  • did you check this link "http://stackoverflow.com/questions/3762200/how-to-keep-an-iphone-app-running-on-background-fully-operational" and give me some explination – Nag_iphone Feb 12 '14 at 07:44
1

Background processing is only allowed to a maximum of 10 minutes in ios unless your app is of one of the following types..

  • Apps that play audible content to the user while in the background, such as a music player app
  • Apps that keep users informed of their location at all times, such as a navigation app
  • Apps that support Voice over Internet Protocol (VoIP)
  • Newsstand apps that need to download and process new content
  • Apps that receive regular updates from external accessories

Refer the following for more info..

http://docs.xamarin.com/guides/cross-platform/application_fundamentals/backgrounding/part_3_ios_backgrounding_techniques/ios_backgrounding_with_tasks/

https://stackoverflow.com/a/9738707/919545

Community
  • 1
  • 1
Ankit Srivastava
  • 12,347
  • 11
  • 63
  • 115
  • My question is --> How can i kept alive the my URL request upto my videos are downloaded in background mode? – Nag_iphone Feb 12 '14 at 07:34