I have an app for iOS and OSX which uses iCloud for syncing Coredata. In iOS its working well i think. The problems comes with the OSX version. The code used in the two versions is practically the same.
I have this in my AppDelegate:
- (NSPersistentStoreCoordinator *)persistentStoreCoordinator
{
if (_persistentStoreCoordinator != nil) {
return _persistentStoreCoordinator;
}
NSURL *storeURL = [[self applicationDocumentsDirectory] URLByAppendingPathComponent:@"myStore.sqlite"];
NSURL *cloudRootURL=[fileManager URLForUbiquityContainerIdentifier:nil];
NSString *pathToCloudFile = [[cloudRootURL path]stringByAppendingPathComponent:@"Documents"];
pathToCloudFile = [pathToCloudFile stringByAppendingPathComponent:@"myAppCloudLogs1"];
NSURL *cloudURL = [NSURL fileURLWithPath:pathToCloudFile];
NSString *cloudStoreTitle = @"myStoreCloud";
NSDictionary *options = @{NSMigratePersistentStoresAutomaticallyOption : @YES,
NSInferMappingModelAutomaticallyOption : @YES,
NSPersistentStoreUbiquitousContentURLKey: cloudURL,
NSPersistentStoreUbiquitousContentNameKey: cloudStoreTitle};
NSError *error = nil;
_persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]];
if (![_persistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) {
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
abort();
}
NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];
[notificationCenter addObserver:self
selector:@selector(processStoresWillChange:)
name:NSPersistentStoreCoordinatorStoresWillChangeNotification
object:_persistentStoreCoordinator];
[notificationCenter addObserver:self
selector:@selector(processStoresDidChange:)
name:NSPersistentStoreCoordinatorStoresDidChangeNotification
object:_persistentStoreCoordinator];
[notificationCenter addObserver:self
selector:@selector(processContentChanges:)
name:NSPersistentStoreDidImportUbiquitousContentChangesNotification
object:_persistentStoreCoordinator];
return _persistentStoreCoordinator;
}
In both applications, when are started I can see the logs stored in the documents directory of the iCloud drive. There are 2 folders, 1 with my name (mac) and one with mobile simulator. When i create a new record in the simulator i can see new transaction log created in the simulator folder. But this change is not being reflected at my os x app. I think the transaction logs are not being replicated to other devices. Each device is only listening for changes in its folder. How can i do so each device listen for changes at others? Is there any way so all the transaction logs are saved at the same folder for all devices?
When running the os x app i get this error message:
[PFUbiquitySetupAssistant canReadFromUbiquityRootLocation:]_block_invoke690(1489): CoreData: Ubiquity:
Attempting to download Peers hit a serious error for peers to download Error Domain=BRCloudDocsErrorDomain Code=5
No document at URL UserInfo=0x600000472f40 {NSDescription=No document at URL,
NSFilePath=/Users/myName/Library/Mobile Documents/iCloud~myGroup~myApp/Documents/myAppCloudLogs1/.DS_Store, NSUnderlyingError=0x600000251340 } with userInfo {
NSDescription = "No document at URL";
NSFilePath = "/Users/myName/Library/Mobile Documents/iCloud~myGroup~myApp/Documents/myAppCloudLogs1/.DS_Store";
NSUnderlyingError = "Error Domain=NSPOSIXErrorDomain Code=2 UserInfo=0x600000472fc0 {NSDescription=No such file or directory}";
}
Why am i getting this error?? What is .DS_Store file? In my ICloud Drive folders i only see .cdt files.
Need help please. Thanks in advance.