简体   繁体   English

当应用程序崩溃时,IOS App CoreData会重置

[英]IOS App CoreData is reset when app crashes

On the device when the application is running and an error occurs, the application is closed and back to start, and sometimes the data I saved in CoreData has been removed. 在设备上运行应用程序并发生错误时,应用程序将关闭并重新启动,有时我保存在CoreData的数据已被删除。 I am currently using MagicalRecord (2.2) to CoreData 我目前正在使用MagicalRecord (2.2)CoreData

An example of how I'm using CoreData with MagicalRecord : 我如何在CoreData使用CoreDataMagicalRecord

- (void)deletePlaylistData:(NSDictionary *)playlist {

   PlaylistOffline *object = [PlaylistOffline MR_findFirstByAttribute:@"id" withValue:playlist[@"id"]];

   if (object) {

      [object MR_deleteEntity];
      [[NSManagedObjectContext MR_defaultContext] MR_saveToPersistentStoreAndWait];

   } else {
       NSLog(@"Error al eliminar Playlist");
   }
}

I'm new to Objective-C and I hope your help thanks, Excuse my English by Google translator 我是Objective-C的新手,我希望你的帮助谢谢,请原谅我的英语谷歌翻译

No crash will cause data to be deleted from disk. 没有崩溃会导致数据从磁盘中删除。 There is simply no connection between the two. 两者之间根本没有联系。

If you are creating objects but not saving them via -[NSManagedObjectContext save:] then they are not being written to disk. 如果您正在创建对象但未通过-[NSManagedObjectContext save:]它们,则它们不会写入磁盘。

If you are using UIManagedDocument , stop. 如果您使用的是UIManagedDocument ,请停止。 Use the template provided Core Data stack from Apple. 使用Apple提供的模板Core Data堆栈。

But, in the end, do what @Wain suggested. 但是,最后,做@Wain建议的事情。 Fix the crash. 修复崩溃。

If you are getting a crash as part of the save, then post the crash log so we can assist with that. 如果您在保存过程中遇到崩溃,请发布崩溃日志,以便我们协助解决。

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

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