I try to sync core data between IOS and OSX. At both apps I have the same configuration:
And the same entitlements:
I also use the same code for the store coordinator within the same name for sqlite file and url:
NSManagedObjectModel* managedModel = [NSManagedObjectModel mergedModelFromBundles:nil];
NSPersistentStoreCoordinator* storeCooordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:managedModel];
//-> start iCloud
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL* applicationFilesDirectory = [JHDCoreDataDAO applicationFilesDirectory];
NSURL* storeURL = [applicationFilesDirectory URLByAppendingPathComponent:DATABASE_NAME];
if(!storeURL) { NSLog(@"Error reading applicationFilesDirectory for given sqlite resouce"); }
NSString* containerIdentifier = [NSString stringWithFormat:@"%@.%@",TEAM_IDENTIFIER,APP_IDENTIFIER];
NSURL* iCloud = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:containerIdentifier];
NSString *iCloudEnabledAppID = @"TEAMID~com~sample~sample";
NSError* persistentStoreError;
if (iCloud) {
NSLog(@"iCloud is working");
NSLog(@"iCloudEnabledAppID = %@",iCloudEnabledAppID);
NSLog(@"iCloud URL: %@",iCloud);
NSString* cloudPath = [[iCloud path] stringByAppendingPathComponent:@"data"];
NSURL* transactionsLogUrl = [NSURL fileURLWithPath:cloudPath];
NSDictionary* options = [NSDictionary dictionaryWithObjectsAndKeys:
iCloudEnabledAppID, NSPersistentStoreUbiquitousContentNameKey,
transactionsLogUrl, NSPersistentStoreUbiquitousContentURLKey,
[NSNumber numberWithBool:YES], NSMigratePersistentStoresAutomaticallyOption,
[NSNumber numberWithBool:YES], NSInferMappingModelAutomaticallyOption,
nil];
[storeCooordinator lock];
if(![storeCooordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&persistentStoreError])
{
NSLog(@"Fehler: %@, %@", persistentStoreError.localizedDescription, persistentStoreError.userInfo);
abort();
}
[storeCooordinator unlock];
} else {
//Handle local psc
}
});
Each app, the IOS Version and the OSX Version, are still running perfectly within the iCloud. Each app handle its own database, due to there is no sync between this two apps. Is there somethings what I have forgotton?
sample.sample.sample
and in your code its `com.sample.sample' – Duncan Groenewald