Nag_iphone
Nag_iphone

Reputation: 967

Videos are downloaded up to 10 min only when app goes to background mode in iOS-7

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;
                          }];

 }

Upvotes: 0

Views: 600

Answers (3)

jcesarmobile
jcesarmobile

Reputation: 53301

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:

Upvotes: 2

Raz
Raz

Reputation: 2643

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.

Upvotes: 1

Ankit Srivastava
Ankit Srivastava

Reputation: 12405

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

Upvotes: 1

Related Questions