The completion handler is not called on iOS7 GM

I am using AVAssetWriter and it works great on iOS6.

The problem is that when I called finishWritingWithCompletionHandler , the completion handler is not called in iOS7 GM.

I called markAsFinished and even endSessionAtSourceTime before I call finalWritingWithCompletionHandler.

It works great on iOS6.

And even more, on iOS7, it works several times, and then it does not work again.

I don’t know why, but it works if I call a method using a warning. So I tried performSelectorOnMainThread and inBackground , but that didn't help.

Any ideas?

+18
ios7 completionhandler avassetwriter
Sep 14 '13 at 12:56 on
source share
5 answers

Apparently you need to save the resource-resource now.

You can try to save with a strong property and see if your completion handler is called. (Be sure to run this property in the completion handler.)

+38
Sep 17 '13 at 19:15
source share

Ray Fix, you're right. We need to save assetWriter. The easiest way is to use it inside the finalWritingWithCompletionHandler block:

  NSError *error = nil; AVAssetWriter *videoWriter = [[AVAssetWriter alloc] initWithURL:[NSURL fileURLWithPath:path] fileType:AVFileType3GPP error:&error]; //startWriting, session etc. [videoWriter finishWritingWithCompletionHandler:^{ NSLog(@"%@",videoWriter); NSLog(@"Write Ended"); }]; 
+8
Nov 07 '13 at 9:17
source share

Keeping an assistant is very important, but I also encountered a very strange intermittent failure, although my assistants were saved (and never reused). The problem also was not a file name conflict or a missing directory, because my file names are based on CACurrentMediaTime () and do not change directories.

You don't seem to set endSessionAtSourceTime: for assembler every time, there is a very rare (but reproducible) chance that the completion handler for finishWritingWithCompletionHandler: will never be called. If you wait a few seconds and check the status of the assistant, it will be in the AVAssetWriterStatusFailure state, and the error will not be described as "Unknown error (-12763)." In addition, changing the file format for the assistant does not affect this problem. Finally, this problem is probably only a problem if you need to quickly record movies again and again (since the probability of failure is probably 1/15 - 1/20).

So, just remember to save the presentation timestamp for the last sample that you pass to the assistant and call endSessionAtSourceTime: with that fetch time right before you call finishWritingWithCompletionHandler:

+3
May 30 '14 at 23:34
source share

This also happens on ARC.

The simplest solution is to define the properties of AVAssetWriter (and the intended AVAssetReader)

 @property(nonatomic,strong) AVAssetWriter *assetWriter; @property(nonatomic,strong) AVAssetReader *assetReader; 

and then

 self.assetWriter = [AVAssetWriter assetWriterWithURL:destURL fileType:AVFileTypeWAVE error:&assetError]; 

and in the completion block

  [assetWriterInput markAsFinished]; [assetWriter finishWritingWithCompletionHandler:^{ [assetReader cancelReading]; completionBlock(self); }]; 
+3
08 Oct '14 at 16:09
source share

This can also happen if the destination directory does not exist. In this case, the recording works fine, but the file is not created and the block is not called.

+1
Mar 10 '14 at 8:12
source share



All Articles