Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/26.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
重启应用程序后iOS上的随机数据丢失_Ios_Objective C_Iphone_Xcode_Load - Fatal编程技术网

重启应用程序后iOS上的随机数据丢失

重启应用程序后iOS上的随机数据丢失,ios,objective-c,iphone,xcode,load,Ios,Objective C,Iphone,Xcode,Load,很明显,我一定是做得不对,但这是随机发生的。我无法通过执行某些步骤来显示问题,因此调试变得非常困难。我有一个应用程序,每次添加或删除对象时,它都会将文件写入plist。我可以在模拟器中验证plist,每次调用save函数时,我都有一个NSLog。在调用applicationWillEnterForeground时加载数据,该应用程序也正常工作。在某些情况下,启动应用程序后,它将恢复到最近更改之前的上一次保存。iOS是否缓存数据文件?如果它试图将文件从磁盘加载到阵列中,是否可能以前的加载已经存在于

很明显,我一定是做得不对,但这是随机发生的。我无法通过执行某些步骤来显示问题,因此调试变得非常困难。我有一个应用程序,每次添加或删除对象时,它都会将文件写入plist。我可以在模拟器中验证plist,每次调用save函数时,我都有一个NSLog。在调用applicationWillEnterForeground时加载数据,该应用程序也正常工作。在某些情况下,启动应用程序后,它将恢复到最近更改之前的上一次保存。iOS是否缓存数据文件?如果它试图将文件从磁盘加载到阵列中,是否可能以前的加载已经存在于缓存中,并使用该数据创建阵列

保存方法:

- (void)saveFile {
    // saves data to file

    NSLog(@"save file reached");
#ifdef LITE_VERSION

    [self.aquariums writeToFile:[self dataFilePathLite] atomically:YES];

#else

    [self.aquariums writeToFile:[self dataFilePath] atomically:YES];

#endif
}
荷载法;我刚刚添加了
if(self.maryanics==null)
检查,它可能已经解决了问题,但我很难确认,因为我无法重新创建问题:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    /*
     Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
     */

    NSLog(@"applicationDidBecomeActive called");

if (self.aquariums == NULL) {
    NSLog(@"aquariums null, loading file");

    #ifdef LITE_VERSION
        NSString *filePath = [self dataFilePathLite];
    #else
        NSString *filePath = [self dataFilePath];
    #endif

        if ([[NSFileManager defaultManager] fileExistsAtPath:filePath]) {
            NSMutableArray *array = [[NSMutableArray alloc] initWithContentsOfFile:filePath];
            self.aquariums = array;
            [array release];

            [self update21];

        } else {

    #ifdef LITE_VERSION
            [self convertFileName];

    #else
            [self update20];
    #endif
        }

        application.applicationIconBadgeNumber = 0;

        if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
            aquaPlannerAppDelegate_iPad *appDelegate = [[UIApplication sharedApplication] delegate];
            [appDelegate.rootView viewDidAppear:YES];
        }
}
}

发布后,未收到任何数据丢失报告,该问题肯定已经解决

if (self.aquariums == NULL) {
因此,人们记得,当应用程序从后台返回时,如果要重新加载数据,请先将其设置为null,然后释放

aquariums = NULL;
[aquariums release];

您是否已经在加载功能和保存功能中记录了文件路径?您需要修改保存方法,以如下相同的方式设置文件路径。在最新的4.3操作系统中,有些人报告数据丢失,加载和保存工作正常,因此文件路径是正确的,只是在保存方法中我没有创建字符串。数据丢失发生在我看来是随机的东西上,应用程序加载的是以前的保存,而不是最近的保存。您是否检查了模拟器的实际文件系统以验证文档内容~/库/应用程序支持/iPhone模拟器/4.3/YourApp/Documents/file system实时检查。我将在xcode中打开plist,它将正确更改。我还没有在模拟器上出现问题。是否有可能应用程序在尝试保存时崩溃?