0

我在应用商店有一个 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);
        }

}

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

4

1 回答 1

0

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

于 2014-10-15T20:50:05.923 回答