繁体   English   中英

iOS更新后如何阻止用户丢失Core Data文件

[英]How to stop user losing Core Data file after iOS update

我在应用商店上有一个ios应用,在最新升级中,用户丢失了数据。 对于此版本,我不得不更改用户的sqlite文件的位置(长话短说)。 原始文件位于\\ Documents \\ myApp.sqlite中。 升级后,我将其复制到\\ Documents \\ myAppDB.sqlite。 代码大部分显示在下面,其中商店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);
        }

}

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM