我有视频网址,并想使用此URl将其从iPhone中删除 [英] I have video URL and want to delete it from the iPhone using this URl
问题描述
我已经创建了一个存储视频的应用,现在我想在用户单击删除"按钮时删除该视频.我正在使用AVFoundation
录制视频.
I have created a app that stores video, now I want to remove that video when a user clicks a remove button. I am using AVFoundation
for record video.
我的应用程序摄像头为我提供了这样的输出网址:
My app camera gives me an output URL like this:
file://localhost/private/var/mobile/Applications/4B2E02E5-3EE2-493E-8ECF-4B1DA29B9387/tmp/output.mov
我已经尝试过了,但是没有用:
I have tried this but it did not work:
- (void) removeFile:(NSURL *)fileURL
{
NSString *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]);
}
}
编辑
- (IBAction)videoWillDelete:(id)sender {
NSString *strPath = [NSHomeDirectory() stringByAppendingPathComponent:@"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);
}
}
}
我的日志文件具有:
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
此功能是我用来在iPhone中存储数据的功能:
This function is what I use to store data in the 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];
}
}
推荐答案
答案很简单, 您不能从文档目录中删除文件.其仅可读和可写.
answer is Simple, you cannot delete file from Document Directory. Its Readable and writeable only.
通过提供tmp目录的路径,然后出于保存目的,将其从tmp路径移至文档目录,可以实现您的目的.而已.
You can achieve your purpose by giving path for tmp directory , and then for saving purpose move it from the tmp path to document directory. Thats it.
这篇关于我有视频网址,并想使用此URl将其从iPhone中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!