我已经写了一些代码来将应用程序包中的文件(dbtemplate.sqlite)复制到库中。但是,库中没有显示文件,每次启动应用程序时都会记录它复制模板的文本。控制台中没有显示错误。我究竟做错了什么?为什么NSFileManager无法正常工作?
NSFileManager *fileManager = [NSFileManager defaultManager];
if (![fileManager fileExistsAtPath:@"~/Library/AppSafe/database/db.sqlite"]) {
[fileManager createDirectoryAtPath:@"~/Library/AppSafe/database" withIntermediateDirectories:YES attributes:nil error:nil];
[fileManager copyItemAtPath:@"dbtemplate.sqlite" toPath:@"~/Library/AppSafe/database/db.sqlite" error:nil];
NSLog(@"copied template");
}
或者,更可靠地向NSFileManager请求应用程序支持中相关文件夹的路径。打开沙箱后,可能会/将会对某个路径进行硬编码(某些路径将会,某些路径可能会中断)。 –
这是你的问题。 – SevenBits