J'ai l'URL de la video et je veux le supprimer de l'iPhone en utilisant cette URL

J'ai créé une application qui stocke la video, maintenant je veux supprimer cette video quand un user clique sur un button de suppression. J'utilise AVFoundation pour la video d'logging.

Mon appareil photo d'application me donne une URL de sortie comme ceci:

 file://localhost/private/var/mobile/Applications/4B2E02E5-3EE2-493E-8ECF-4B1DA29B9387/tmp/output.mov 

J'ai essayé mais ça n'a pas marché:

 - (void) removeFile:(NSURL *)fileURL { NSSsortingng *filePath = [fileURL path]; NSFileManager *fileManager = [NSFileManager defaultManager]; if ([fileManager fileExistsAtPath:filePath]) { NSLog(@"here it is : %@",fileURL); NSError *error; // Attempt to delete the file at filePath2 if ([fileManager removeItemAtPath:filePath error:&error] != YES) NSLog(@"Unable to delete file: %@", [error localizedDescription]); // Show contents of Documents directory NSLog(@"Documents directory: %@", [fileManager contentsOfDirectoryAtPath:filePath error:&error]); } } 

MODIFIER

  - (IBAction)videoWillDelete:(id)sender { NSSsortingng *strPath = [NSHomeDirectory() ssortingngByAppendingPathComponent:@"output.mov"]; NSLog(@"file is:%@",strPath); if ([[NSFileManager defaultManager] isDeletableFileAtPath:strPath]==YES) { NSLog(@"file is deletebale"); }else { NSLog(@"file is not deletebale"); } NSError *error; if ([[NSFileManager defaultManager] isDeletableFileAtPath:strPath]) { BOOL success = [[NSFileManager defaultManager] removeItemAtPath:strPath error:&error]; if (!success) { NSLog(@"Error removing file at path: %@", error.localizedDescription); } } } 

Mon file journal a:

 2012-11-02 17:33:21.836 AVFoundationCam[1791:707] file is:/var/mobile/Applications/4B2E02E5-3EE2-493E-8ECF-4B1DA29B9387/output.mov 2012-11-02 17:33:21.838 AVFoundationCam[1791:707] file is not deletebale 

Cette fonction est ce que j'utilise pour stocker des données dans l'iPhone:

 else { ALAssetsLibrary *library = [[ALAssetsLibrary alloc] init]; [library writeVideoAtPathToSavedPhotosAlbum:outputFileURL completionBlock:^(NSURL *assetURL, NSError *error) { if (error) { if ([[self delegate] respondsToSelector:@selector(captureManager:didFailWithError:)]) { [[self delegate] captureManager:self didFailWithError:error]; } } if ([[UIDevice currentDevice] isMultitaskingSupported]) { [[UIApplication sharedApplication] endBackgroundTask:[self backgroundRecordingID]]; } if ([[self delegate] respondsToSelector:@selector(captureManagerRecordingFinished:)]) { [[self delegate] captureManagerRecordingFinished:self]; } }]; //[library release]; } } 

Vous pouvez get le path Directory Document comme suit:

 NSSsortingng *strPath = [NSHomeDirectory() ssortingngByAppendingPathComponent:@"Documents"]; 

Maintenant, supprimez l'élément comme ceci:

 NSError *error; if ([fileManager fileExistsAtPath:path]) { if ([[NSFileManager defaultManager] isDeletableFileAtPath:strPath]) { BOOL success = [[NSFileManager defaultManager] removeItemAtPath:strPath error:&error]; if (!success) { NSLog(@"Error removing file at path: %@", error.localizedDescription); } else { NSLog(@"File removed at path: %@", error.localizedDescription); } } else { NSLog(@"file not exists"); } 

Cochez [NSHomeDirectory() ssortingngByAppendingPathComponent:@"tmp/output.mov"]; est la même chose avec outputFileURL dans [library writeVideoAtPathToSavedPhotosAlbum:outputFileURL completionBlock:^(NSURL *assetURL, NSError *error) {

la réponse est simple, vous ne pouvez pas supprimer le file du directory de documents. C'est lisible et inscriptible seulement.

Vous pouvez atteindre votre but en donnant le path pour le directory tmp, puis, à des fins de sauvegarde, le déplacer du directory tmp vers le directory du document. C'est tout.