ios - iOS上传后如何删除压缩视频?
<p><p>在我的应用程序中,当我选择一个视频并对其进行压缩后,系统会创建两个文件。当我选择另一个文件时,它会再次复制它。这增加了我的内存空间。现在我想从系统中删除文件的压缩版本。谁能帮我做这件事?</p>
<p>这是我的 ImagePickerController 委托(delegate)</p>
<pre><code>#pragma mark - UIImagePicker delegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *mediaType = ;
if (CFStringCompare ((__bridge CFStringRef) mediaType, kUTTypeMovie, 0) == kCFCompareEqualTo) {
NSURL *videoUrl=(NSURL*);
NSString *moviePath = ;
if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
UISaveVideoAtPathToSavedPhotosAlbum (moviePath, nil, nil, nil);
NSURL *videoURL = ;
isVideoShooted =NO;
;
}
}
[self dismissViewControllerAnimated:YES completion:^{
}];
}
</code></pre>
<p>我得到的videoURL是</p>
<p>file:///Users/webwerks/Library/Developer/CoreSimulator/Devices/17B6B1EB-8015-4747-81B0-6FB07F713471/data/Containers/Data/Application/18A3DB9A-78CE-4761-A4EB-B35CBFCEF1C5/tmp/修剪.A8DC422C-137F-4FF9-878A-E175CE4DDF8F.MOV</p>
<p>当我上传压缩视频时,我正在使用以下代码删除此路径中的文件</p>
<pre><code>+ (void)clearTmpDirectory
{
NSArray* tmpDirectory = [ contentsOfDirectoryAtPath:NSTemporaryDirectory() error:NULL];
for (NSString *file in tmpDirectory) {
if ([isEqualToString:@"MOV"])
[ removeItemAtPath: error:NULL];
}
}
</code></pre>
<p>这段代码运行良好,它从路径中删除了视频,但我仍然在照片应用程序中获得了一个视频文件。每次我上传视频时,都会不断生成文件。现在我不想在照片中创建重复文件,否则它应该在上传后被删除。</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您不必使用 <code>UISaveVideoAtPathToSavedPhotosAlbum</code>。它会使视频文件被复制。</p>
<pre><code>if (UIVideoAtPathIsCompatibleWithSavedPhotosAlbum (moviePath)) {
NSURL *videoURL = ;
isVideoShooted =NO;
;
}
</code></pre></p>
<p style="font-size: 20px;">关于ios - iOS上传后如何删除压缩视频?,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/39874107/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/39874107/
</a>
</p>
页:
[1]