我的应用程序允许用户创建预设并将它们保存为文件Application support
夹中的二进制文件。如果我的应用程序以一些预定义的预设开始,那就太好了,但我不知道如何设置应用程序以在首次启动时安装此文件。
我是否必须将此文件放入项目中,然后在首次启动时移动它们?这是一个好习惯吗?
我们在我们的项目中这样做 - 我们在应用程序开始时检查文件是否存在。
NSString* fileName = @"...";
NSArray* dirs = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
dbPath = [[dirs objectAtIndex:0] stringByAppendingPathComponent:fileName];
// check if DB exist in correct location
NSFileManager* fileManager = [NSFileManager defaultManager];
success = [fileManager fileExistsAtPath:dbPath];
if(!success)
{
NSString *path = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:fileName];
[fileManager copyItemAtPath:path toPath:dbPath error:nil];
}