Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extending Background Task timeout period while uploading Large videos iOS [closed]

I have an application in which I have to upload large videos to Amazon s3 bucket. I am using NSOperations regulated by an NSOperationQueue to run concurrent tasks.

I don't have problems when upload small videos (smaller then 200 Mb). But the problem is when i try to upload a large video, after 10 minutess the upload process gets interrupted.

I'm already using beginBackgroundTaskWithExpirationHandler:^ to get a window of 10 mins. What is the proper way by which I can extend this timeout period?

Will Apple reject the app if I somehow manage to extend this timeout?

Presently I have the following code in my AppDelegate which I built referring to the link iPhone - Backgrounding to poll for events

  - (void)applicationDidEnterBackground:(UIApplication *)application 
{

    UIApplication*    app = [UIApplication sharedApplication];
    dispatch_block_t expirationHandler;

    expirationHandler = ^{
        bgTask = [app beginBackgroundTaskWithExpirationHandler:expirationHandler];
    };

    bgTask = [app beginBackgroundTaskWithExpirationHandler:expirationHandler];
}

With this piece of code I see that the background task gets never interrupted. As you can see inside the expiration handler, I've initiated another background task event which leads to an infinitely running task. Even though, I can write the logic to end the background task once my upload is finished, but I'm having doubts about this approach..

What do you guys think?

Is it a hack by any means? Will Apple reject the app for following approach?

like image 740
Xcoder Avatar asked Nov 28 '12 08:11

Xcoder


2 Answers

The idea behind background tasks is to prevent applications from continuously running in the background. In other words, if you try to bypass the restrictions that Apple has put into place then they have ground to reject your application.

The question whether they will do this can only be answered by Apple. However, as Daij-Djan mentions, there are other situations in which your application can get killed.

A few months ago, I faced a similar situation, that is, an application had to upload large files to an S3 bucket. The solution is using multipart uploads to make sure that the upload process is resumed whenever your application becomes active. You can read more about multipart uploads in the API reference.

like image 181
Bart Jacobs Avatar answered Oct 24 '22 05:10

Bart Jacobs


it seems hackisch but not bad IMHO (the opposite) :D

if apple lets it go through, you're golden but in fact you are abusing bg tasks

BTW: even with that, ios MAY just cancel you! + dont do CPU intensive/memory intensive work as it will affect the performance of other apps maybe

like image 44
Daij-Djan Avatar answered Oct 24 '22 04:10

Daij-Djan