15

It seems that finishWriting is broken on iOS 6 simulator - it hangs forever. It's now deprecated and replaced by the new finishWritingWithCompletionHandler: - which also never calls the handler.

On real devices running iOS 6, this works just fine as it always did. Also in previous iOS simulators it works just fine. Seems like a bug in iOS 6 simulator.

Anyone else experiencing this or can prove me wrong?

user1574100
  • 171
  • 1
  • 5

2 Answers2

12

I had this issue as well, then realized that I wasn't calling endSessionAtSourceTime: after starting one. This resolved my issue.

Dan Grover
  • 196
  • 2
  • 3
  • 1
    This worked for me too. If you call `finishWritingWithCompletionHandler:` on your `AVAssetWriter` object then you **do have to call** `endSessionAtSourceTime:` before that in order for the completion handler to be invoked. (The documentations states that you don't have to call it if you use `finishWriting`, which has been deprecated since iOS 6.0.) – SolidSun Feb 07 '13 at 17:56
  • Worked for me also. The deadlock didn't always happen, but the output file was never written correctly without the `endSessionAtSourceTime:` call. – Chris Devereux Oct 12 '13 at 22:10
2

Ok found a work around on Simulator.

Looks like stop deadlocks the video processing thread so a workaround is to call stop in the main thread instead:

//      in iOS6 Simulator this blocks the video processing thread call back in UI thread.
//       BOOL stop = [assetWriter finishWriting];
[self performSelectorOnMainThread:@selector(stopInOtherThread) withObject:nil]; 

-(void)stopInOtherThread{
    //Stop doesn't block in MainThread
    BOOL stop = [assetWriter finishWriting];
    NSLog(@" assetWriter finishWriting :%d",stop);
}

This workaround doesn't seem to work for finishWritingWithCompletionHandler

I'll try and see if I can raise a bug on Apple.

Graham
  • 41
  • 4
  • I already posted a bug. The paradox is that since iOS6, if we call finishWriting on the main thread, the log shows: WARNING: -finishWriting should not be called on the main thread. – user1574100 Sep 22 '12 at 16:42
  • I'm having the same problem. iOS6 simulator isn't called the handler, and status never changes off AVAssetWriterStatusWriting. – Tod Cunningham Oct 06 '12 at 17:36
  • 1
    I only started getting this after switching my project to use ARC. – Ray Fix Nov 11 '12 at 05:13