iphone - 一旦 App 进入后台,AVAssetWriter 就会失败

标签 iphone ios objective-c avassetwriter

我正在开发 iOS 应用程序,我在其中从图像创建视频。我正在使用 AVAssetWriter 来实现这一点。一切正常。但是当应用程序进入后台并切换回来时,视频写入失败。当我切换回应用程序时,AVAssetWriterfinishWritingWithCompletionHandler 没有被调用。

可能与 AVAssetWriter fails when Application enters Background during Rendering 重复,但我没有从那里得到任何帮助。

有什么想法吗?

谢谢

最佳答案

此答案基于您希望视频在后台继续呈现的假设。

我在我的应用程序中修复了这个问题,方法是要求操作系统授予应用程序后台任务权限(在有限的时间内)。这个答案也可能对你有帮助 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;
    }];

完成后不要忘记放手!

[[UIApplication sharedApplication] endBackgroundTask:_backgroundRenderingID];

关于iphone - 一旦 App 进入后台,AVAssetWriter 就会失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16353745/

相关文章:

iphone - NSRangeException 错误

iphone - 如何从 url 为直播的相机播放直播

objective-c - 如何在 NSTableView 中重用单元格?

android - chromecast 如何连接到其他设备?

ios - 如何使用用户输入将行添加到 TableView ?

ios - UITableVIew 的 tableViewCell 中看不到 Text Field 和 Labels

ios - 清除 NSMutableArray 以存储新的 json 它

iphone - 使用 UITableViewController 时如何尽量减少重复自己

iphone - 对 NSMutableArray 进行排序

当 iPhone 连接到计算机时,iOS 会访问临时私有(private)文件