I am trying to use a database managed by Core Data and synced with iCloud in my iPhone app.
I have used the sample code from the WWDC 2012 and managed to make it work almost properly.
Also, my database is very simple: there is only one kind of object and no relationship.
Two devices can communicate through iCloud, however, this little scenario fails:
- Create an object on the device A
- Wait that the object appeared on the device B
- Modify the object on the device A
- Modify the object on the device B
- When the device B is aware of the update it tries to merge the changes and the app crashes.
Yes, the app CRASHES. There is only ONE object in my database and Core Data doesn't seem to be able to resolve a tiny little conflict.
Here is how I create my persistent store and with which options:
NSDictionary *options = @{NSPersistentStoreUbiquitousContentNameKey : contentName,
NSPersistentStoreUbiquitousContentURLKey : iCloudLogsPath};
self.iCloudStore = [self.persistentStoreCoordinator
addPersistentStoreWithType:NSSQLiteStoreType
configuration:nil
URL:iCloudData
options:options
error:&error];
And here is the code I use to create a NSManagedObjectContext in background:
- (NSManagedObjectContext*) currentThreadContext {
NSManagedObjectContext *moc = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSPrivateQueueConcurrencyType];
[moc setPersistentStoreCoordinator:self.persistentStoreCoordinator];
[moc setMergePolicy:NSMergeByPropertyStoreTrumpMergePolicy];
return moc;
}
I did add a breakpoint to catch any exceptions, here is what I get:
objc_exception_throw:
[NSPersistentStoreCoordinator executeRequest:withContext:error:]:
[NSManagedObjectContext save:]:
[_PFUbiquityRecordImportOperation main]:
[__NSOperationInternal start]:
[_PFUbiquityRecordsImporter scheduleTransactionLogOperations:synchronous:error:]:
[_PFUbiquityRecordsImporter scanOperationFinished:withDiscoveredLogLocation:error:]:
[PFUbiquityImportScanOperation main]:
[__NSOperationInternal start]:
[_PFUbiquityRecordsImporter scheduleUbiquityRootScan:withLocalPeerLogs:error:]:
[_PFUbiquityRecordsImporter rollResponseOperation:successfullyAdoptedBaseline:]:
[PFUbiquityBaselineRollResponseOperation main]:
[__NSOperationInternal start]:
Any help would be highly appreciated!