【问题标题】:How to stop user losing Core Data file after iOS updateiOS更新后如何阻止用户丢失Core Data文件
【发布时间】:2014-09-15 05:21:03
【问题描述】:

我在应用商店有一个 ios 应用,在最新升级中,用户丢失了数据。对于这个版本,我不得不更改用户的 sqlite 文件的位置(长话短说)。 原始文件位于 \Documents\myApp.sqlite 中。升级后,我将其复制到 \Documents\myAppDB.sqlite。 代码主要如下所示,其中 store url 指向新位置, legacyStoreURL 指向旧位置。

BOOL stillUsingLegacyStore = YES;
stillUsingLegacyStore = !([fileManager fileExistsAtPath:[[self storeURL] path]]);
 if ([fileManager fileExistsAtPath:[[self legacyStoreURL] path]]  && stillUsingLegacyStore==YES)
 {
     _store = [_coordinator addPersistentStoreWithType:NSSQLiteStoreType
                                       configuration:nil
                                                 URL:[self legacyStoreURL]
                                             options:options
                                               error:&error];
     if (!_store)
     {
         FLOG(@"Error adding OLD persistent store to coordinator %@\n%@",
              [error localizedDescription], [error userInfo]);
         return;
     }

     _store = [_coordinator migratePersistentStore:_store
                                           toURL:[self storeURL]
                                         options:options
                                        withType:NSSQLiteStoreType
                                           error:&error];
     if (!_store)
     {
         FLOG(@"Error adding OLD persistent store to coordinator %@\n%@",
              [error localizedDescription], [error userInfo]);
         return;
     }
 }
 else
 {
     _store = [_coordinator addPersistentStoreWithType:NSSQLiteStoreType
                                         configuration:nil
                                                   URL:[self storeURL]
                                               options:options
                                                 error:&error];
     if (!_store)
     {
         NSLog(@"Failed to add store. Error: %@", error);abort();
         return;
     }
        else
        {
            NSLog(@"Successfully added store: %@", _store);
        }

}

我无法在自己的设备上重现该问题。由于我决定不删除原始文件,我希望我可以进行升级以允许用户恢复旧文件。但是,在尝试此操作之前,我真的希望能够理解并重现该问题。谁能弄清楚为什么这可能出错了,以及为什么我无法重现它。

【问题讨论】:

    标签: ios sqlite upgrade data-loss file-location


    【解决方案1】:

    您是否复制了 -wal 和 -shm 文件?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-20
      • 1970-01-01
      • 1970-01-01
      • 2010-09-08
      • 1970-01-01
      • 2018-11-10
      • 2019-12-16
      • 1970-01-01
      相关资源
      最近更新 更多