所以我想弄清楚为什么我不能制作可读的文件副本。我尝试过 moveItemAtPath、copyItemAtPath 和 createFileAtPath。每次,从原始路径读取数据都可以正常工作,但从新文件路径读取数据会导致 0 字节 nil NSdata 对象。
NSData* tempData = [NSData dataWithContentsOfURL:tempSoundFile]; // reads just fine
NSError* error;
NSFileManager* fileMgr = [NSFileManager defaultManager];
NSString* docDir = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];
NSString* uniqueFileName = [[NSString stringWithFormat:@"%@-%@", description.text, [NSDate date]] MD5];
NSString* newAudioFile = [NSString stringWithFormat:@"%@/%@.caf", docDir, uniqueFileName];
if (LOG) { NSLog(@"Copying %@ to %@", tempSoundFile.path, newAudioFile); }
// Have tried either or both as well as moveItemAtPath with the same result
[fileMgr createFileAtPath:newAudioFile contents:tempData attributes:nil];
//[fileMgr copyItemAtPath:tempSoundFile.path toPath:newAudioFile error:&error];
NSData* audioAfter = [NSData dataWithContentsOfURL:[NSURL URLWithString:newAudioFile]]; // nil data
日志输出:
将 /var/mobile/Applications/19531C7F-F408-45B9-B417-09315BB15B49/Documents/8554temp.caf 复制到 /var/mobile/Applications/19531C7F-F408-45B9-B417-09315BB15B49/Documents/933becb02783c8f9c715accad。
有人对我做错了什么有任何建议吗?谢谢