0
我在苹果公司托管我的应用内购买内容。我已经设法下载内容,现在我想将它保存在设备中。iOS - NSFileManager文件不存在
[[NSFileManager defaultManager] removeItemAtPath:dstPath error:nil];
[[NSFileManager defaultManager] copyItemAtPath:srcPath toPath:dstPath error:nil];
上面的代码是我如何将内容下载到我想要的位置。
它似乎工作正常,当我尝试显示它的工作内容。但是,当我停止并再次运行应用程序时,文件不存在。
我错过了什么?
我的代码:
- (void)processDownload:(SKDownload *)download
{
NSString *path = [download.contentURL path];
path = [path stringByAppendingPathComponent:@"Contents"];
NSFileManager *fileManager = [NSFileManager defaultManager];
NSError *error;
NSArray *files = [fileManager contentsOfDirectoryAtPath:path error:&error];
NSMutableArray *stickersDownloadedArray = [[NSMutableArray alloc] init];
for (NSString *file in files)
{
NSString *fullPathSrc = [path stringByAppendingPathComponent:file];
NSString *fileName = [fullPathSrc lastPathComponent];
NSString *fullPathDst = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:[NSString stringWithFormat:@"/%@", fileName]];
[fileManager removeItemAtPath:fullPathDst error:nil];
[fileManager moveItemAtPath:fullPathSrc toPath:fullPathDst error:nil];
NSLog(@"fullPathDst: %@", fullPathDst);
NSLog(@"file: %@", file);
NSLog(@"key: %@", download.transaction.payment.productIdentifier);
[stickersDownloadedArray addObject:fullPathDst];
}
[[NSUserDefaults standardUserDefaults] setObject:stickersDownloadedArray
forKey:download.transaction.payment.productIdentifier];
[[NSUserDefaults standardUserDefaults] synchronize];
}
的fullPathDst
一个例子是在不同的时间
/var/mobile/Containers/Data/Application/E921ADD6-B022-4DA2-8416-627DB44E679A/Documents/[email protected]
你要把数据保存到哪里?你能打印'dstPath'并显示给我们吗? – Sulthan
@Sulthan我已更新我的答案 – tnylee
@Sulthan只要我不停止并再次运行应用程序,该文件就存在。 – tnylee