Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAssetWriter fails once App goes in background

I am working on iOS app in which i am creating video from images. I am using AVAssetWriter to achieve this. Everything works fine. But When app goes in background and switched back, the video writing fails. AVAssetWriter's finishWritingWithCompletionHandler is not getting called when i switch back to app.

May be duplicate of AVAssetWriter fails when Application enters Background during Rendering , but i am not getting any help from there.

Any idea for this?

Thanks

like image 962
Unnati Avatar asked May 03 '13 07:05

Unnati


1 Answers

This answer is based on the assumption that you want the video to continue rendering while in the background.

I fixed this in my app doing by asking the OS to grant the app background task permisions (for a limited amount of time). This answer might help you too iOS generating a video in the background task

    @property (nonatomic,assign) UIBackgroundTaskIdentifier __block backgroundRenderingID;

    UIApplication *app = [UIApplication sharedApplication];

    _backgroundRenderingID = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:_backgroundRenderingID];
        _backgroundRenderingID = UIBackgroundTaskInvalid;
    }];

Don't forget to let go once you are done!

[[UIApplication sharedApplication] endBackgroundTask:_backgroundRenderingID];
like image 177
Javier Quevedo Avatar answered Nov 05 '22 18:11

Javier Quevedo