Cocoa 首次启动时将文件安装到应用程序支持中
我的应用程序允许用户创建预设并将其保存为Cocoa 首次启动时将文件安装到应用程序支持中,cocoa,default,Cocoa,Default,我的应用程序允许用户创建预设并将其保存为应用程序支持文件夹中的二进制文件。如果我的应用程序以一些预定义的预设启动,那就太好了,但是我不知道如何设置应用程序,以便在第一次启动时安装此文件 我必须将这些文件放入项目中,然后在第一次启动时移动它们吗?这是一种好的做法吗 我们在项目中这样做-我们在应用程序开始时检查文件是否存在 NSString* fileName = @"..."; NSArray* dirs = NSSearchPathForDirectoriesInDomains
应用程序支持
文件夹中的二进制文件。如果我的应用程序以一些预定义的预设启动,那就太好了,但是我不知道如何设置应用程序,以便在第一次启动时安装此文件
我必须将这些文件放入项目中,然后在第一次启动时移动它们吗?这是一种好的做法吗 我们在项目中这样做-我们在应用程序开始时检查文件是否存在
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];
}
我们在项目中这样做-我们检查应用程序开始时是否存在文件
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];
}