3

Hi i'm developing an iphone application that creates an AVAssetExportSession object to save and create a video file. All is ok,(the file is created and correctly saved in the documents folder) except when i try to resume a saving process. If i push the home button to exit the app (or if i receive a call or a sms) the method exportAsynchronouslyWithCompletionHandler fail. Apple's documentation say:

"The export will fail if you try to overwrite an existing file, or write a file outside of the application’s sandbox. If you need to overwrite an existing file, you must remove it first. Export may also fail if:

There is an incoming phone call

Your application is in the background and another application starts playback

In these situations, you should typically inform the user that the export failed, then allow the user to restart the export."

So i try to cancel the exportation and then restart it when the user reopen the app. I have this error when exportAsynchronouslyWithCompletionHandler is called for the second time:

" Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Cannot call exportAsynchronouslyWithCompletionHandler: more than once.'"

It seems that after [asset CancelExport] exportAsynchronouslyWithCompletionHandler remains alive,it is possible? I have also tried to export the asset to another view controller for the second time calling but the result is the same. How i can do to repeat saving after an interruption without losing my asset (it's build by another view controller and i can't rebuild it without a new user interaction)?

This is my code:

-(void)save{

[asset exportAsynchronouslyWithCompletionHandler:^
 {
     switch (asset.status) 
     {
         case AVAssetExportSessionStatusCompleted: 
         {


             [self performSelectorOnMainThread:@selector(lanciosuccess) withObject:nil waitUntilDone:NO];

             break;
         }

         case AVAssetExportSessionStatusFailed:
         {

             [asset cancelExport];
             [self performSelectorOnMainThread:@selector(sospendi) withObject:nil waitUntilDone:NO];

             break;
         }
         case AVAssetExportSessionStatusUnknown: 
         {
              NSLog (@"unknow");



             break;
         }
         case AVAssetExportSessionStatusWaiting: 
         {
              NSLog (@"waiting");



             break;
         }
         case AVAssetExportSessionStatusCancelled: 
         {
              NSLog (@"cancelled");



             break;
         }


     };

 }];

}

-(void)sospendi{

if ([[NSFileManager defaultManager] fileExistsAtPath:[asset.outputURL path]]) 
{
    [[NSFileManager defaultManager] removeItemAtPath:[asset.outputURL path] error:nil];
}

[self save];

}

Cri1682
  • 513
  • 8
  • 21
  • It's help me for debug my problem of http://stackoverflow.com/questions/9653241/get-error-code-11843-while-exporting-mp3-file-in-ipod-library-since-ios-5-1 – Nilesh Kikani Mar 21 '12 at 13:55

0 Answers0