Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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
Objective c CFPreferences创建多个文件_Objective C_Cocoa_Preferences - Fatal编程技术网

Objective c CFPreferences创建多个文件

Objective c CFPreferences创建多个文件,objective-c,cocoa,preferences,Objective C,Cocoa,Preferences,我只有一个小问题: 为什么CFPreferences API在my UserPrefs目录中创建多个文件?所有文件都以my Bundle标识符作为名称,并且所有文件(除原始文件外)都添加了如下后缀: 这看起来很像原子写入的副作用 原子写入意味着,每当从NSData(或其他)对象写入文件时,首先使用同一目录中的临时文件名创建该文件。然后将所有数据写入该文件(这是一种通常不是原子的操作)。关闭文件后,它将重命名为原始文件名。重命名是一个原子步骤,它确保可能查看该文件的任何其他进程都可以看到完整的旧

我只有一个小问题:

为什么CFPreferences API在my UserPrefs目录中创建多个文件?所有文件都以my Bundle标识符作为名称,并且所有文件(除原始文件外)都添加了如下后缀:


  • 这看起来很像原子写入的副作用

    原子写入意味着,每当从
    NSData
    (或其他)对象写入文件时,首先使用同一目录中的临时文件名创建该文件。然后将所有数据写入该文件(这是一种通常不是原子的操作)。关闭文件后,它将重命名为原始文件名。重命名是一个原子步骤,它确保可能查看该文件的任何其他进程都可以看到完整的旧文件或完整的新文件。进程不可能只看到文件的一半


    有趣的命名文件看起来像是这个过程中的工件。也许你的应用程序在原子写的中间崩溃了?

    如果你在关闭应用程序时做同步,例如:

    - (void)applicationWillResignActive:(UIApplication *)application
    {
        [[NSUserDefaults standardUserDefaults] synchronize];
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
    }
    
    它将首先尝试写入虚拟文件,然后进行原子重命名。如果写入需要很长时间,您将得到一个虚拟文件

    在我的例子中,我有一些用户有14mb的plists,结果有很多虚拟文件(几乎占用2G)


    我的问题和解决方法是压缩我写入userdefaults的图像。

    Hi,我只是想知道首选项文件位于哪里,如果您选择使用
    kCFPreferencesAnyUser
    ?谢谢