0

Before anyone suggests, we are using one managedObjectContext for [context save:&error];

We are saving a new object in Core Data with iOS5.

The issue is, the first time we save a new object, NSManagingContextDidSaveChangesNotification fires and the [[notification userInfo] objectForKey:NSUpdatedObjectsKey] gives back an unpopulated object. In iOS6, objectForKey:NSUpdatedObjectsKey is populated.

Afterwards when we save objectForKey:NSUpdatedObjectsKey is populated.

The context we are always using is [[UIApplication sharedApplication] delegate].mainDocument.managedObjectContext.

So the issue is, the first time [context save:&error] is called, nothing is saved to the db. But it has been saved to the object, so the next time [context save:&error] is called it gets put in the db.

Does anyone have any info on this. I've heard tell of bugs in CoreData in iOS5 , so if anyone has any advice we would appreciate it.

Mundi
  • 79,884
  • 17
  • 117
  • 140
mylegfeelsfunny
  • 507
  • 1
  • 8
  • 20
  • I've located the problem. We are saving the image to the asset library using ALAssetsLibrary and the first time you do this in iOS5, Apple prompts the user with "... Would like to Use Your Curent Location" for the metadata of whatever you are saving. This alert prevents the context from saving. This was proven by turning location services off and it saved without issue. It also explains why it happened only on the first time we saved it, we don t get the alert after the first time. – mylegfeelsfunny May 03 '13 at 19:27

1 Answers1

0

Check these items in the given order:

  • Make sure the object is already populated when you save it the first time (e.g. NSLog).
  • Make sure you query the notifications's userInfo properly.
  • Make sure at this point that the physical database does not contain the proper information (e.g. via sqlite3 command line tool)
  • Make sure you output the correct object whenever you check if it is populated or not.
Mundi
  • 79,884
  • 17
  • 117
  • 140