我正在开发 iOS 应用程序,我在其中从图像创建视频。我正在使用 AVAssetWriter
来实现这一点。一切正常。但是当应用程序进入后台并切换回来时,视频写入失败。当我切换回应用程序时,AVAssetWriter
的 finishWritingWithCompletionHandler
没有被调用。
可能与 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/