Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/cocoa/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cocoa 首次启动时将文件安装到应用程序支持中_Cocoa_Default - Fatal编程技术网

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];

    }