gpt4 book ai didi

ios - iPhone 复制文件

转载 作者:行者123 更新时间:2023-11-29 01:35:52 26 4
gpt4 key购买 nike

我使用以下代码创建两个文件路径:

NSString *fileName = [[self genRandStringLength:15] stringByAppendingString:@".mp4"];
NSString *finalFilePath = [self.videoFiles stringByAppendingString:fileName];

NSString *tmpFile = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp.mp4"]];
[[NSFileManager defaultManager] removeItemAtPath:tmpFile error:NULL];

然后我有一些代码来创建视频文件,我想将它保存在文档文件夹中:

[[NSFileManager defaultManager] copyItemAtPath:tmpFile toPath:finalFilePath error:&err];

我收到此错误:

Error Domain=NSCocoaErrorDomain Code=4 "The file “temp.mp4” doesn’t exist." 
UserInfo={NSSourceFilePathErrorKey=/private/var/mobile/Containers/Data/Application/E5B7BBCB-311F-41A3-949D-8A309F535C95/tmp/temp.mp4, NSUserStringVariant=(
Copy
), NSDestinationFilePath=/var/mobile/Containers/Data/Application/E5B7BBCB-311F-41A3-949D-8A309F535C95/Documents/VideoFiles/0iWDmhLvbbzM6SE.mp4, NSFilePath=/private/var/mobile/Containers/Data/Application/E5B7BBCB-311F-41A3-949D-8A309F535C95/tmp/temp.mp4, NSUnderlyingError=0x12f0099b0 {Error Domain=NSPOSIXErrorDomain Code=2 "No such file or directory"}}

知道问题出在哪里吗?

只是为了一些检查,我尝试将视频复制到 iPhone 照片库:UISaveVideoAtPathToSavedPhotosAlbum(tmpFile, self, nil, nil);

工作正常,因此文件存在。

最佳答案

使用此代码

NSString *fileName = [[self genRandStringLength:15] stringByAppendingString:@".mp4"];
NSString *finalFilePath = [self.videoFiles stringByAppendingString:fileName];

NSString *tmpFile = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp.mp4"]];

NSFileManager *fileManager = [NSFileManager defaultManager];

BOOL success = [fileManager fileExistsAtPath:tmpFile];

if (success)
{
[[NSFileManager defaultManager] copyItemAtPath:tmpFile toPath:finalFilePath error:&err];

[[NSFileManager defaultManager] removeItemAtPath:tmpFile error:NULL];

}

关于ios - iPhone 复制文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32980335/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com