AVAssetWriter进入后台回到前台处理

397 阅读1分钟

AVAssetWriter进入后台再回到前台会报错,此时如果在进行塞入输入会直接失败。

解决方案

在进入后台过程中开启iOS的后台长任务,保证AVAssetWriter状态正常。

具体代码

- (void)applicationDidEnterBackground:(NSNotification *)note
{
    UIApplication *app = [UIApplication sharedApplication];
    _backgroundRenderingID = [app beginBackgroundTaskWithExpirationHandler:^{
        [app endBackgroundTask:_backgroundRenderingID];
        _backgroundRenderingID = UIBackgroundTaskInvalid;
    }];
 NSTimeInterval time1 = app.backgroundTimeRemaining; //180s
}
[[UIApplication sharedApplication] endBackgroundTask:_backgroundRenderingID];