简体   繁体   中英

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. I am currently using MagicalRecord (2.2) to CoreData

An example of how I'm using CoreData with MagicalRecord :

- (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

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.

If you are using UIManagedDocument , stop. Use the template provided Core Data stack from Apple.

But, in the end, do what @Wain suggested. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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