0

アプリがバックグラウンドに移行したときに、ビデオを GPUImage videoCamera からカメラ ロールに保存する際に問題が発生しています。ファイルは、アプリがフォアグラウンドに戻ったとき/再起動されたときにのみカメラロールに保存されます。私は間違いなく初心者のコードエラーを作成しています。誰かがそれを指摘できれば幸いです。

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

if (isRecording){
    [self stopRecording];
};
if (self.isViewLoaded && self.view.window){
    [videoCamera stopCameraCapture];
};
runSynchronouslyOnVideoProcessingQueue(^{
    glFinish();
});
NSLog(@"applicationDidEnterBackground");

その後

-(void)stopRecording {
[filterBlend removeTarget:movieWriter];
videoCamera.audioEncodingTarget = nil;
[movieWriter finishRecording];
NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:@"file.mov"];
ALAssetsLibrary *al = [[ALAssetsLibrary alloc] init];
[al writeVideoAtPathToSavedPhotosAlbum:[NSURL fileURLWithPath:path] completionBlock:^(NSURL *assetURL, NSError *error) {
    if (error) {
        NSLog(@"Error %@", error);
    } else {
        NSLog(@"Success");
    }

}];
isRecording = NO;
NSLog(@"Stop recording");
4

1 に答える 1

1

Brad がいつものように、彼の洞察に満ちたコメントで指摘したとおりでした。

self.backgroundTask = [[UIApplication sharedApplication] beginBackgroundTaskWithExpirationHandler:^{
    NSLog(@"Background handler called. Not running background tasks anymore.");
    [[UIApplication sharedApplication] endBackgroundTask:self.backgroundTask];
    self.backgroundTask = UIBackgroundTaskInvalid;
}];

@property (nonatomic) UIBackgroundTaskIdentifier backgroundTask;

http://www.raywenderlich.com/29948/backgrounding-for-iosでこのソリューションを見つけました

于 2013-10-31T21:16:05.843 に答える