4

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.

user3065901
  • 4,678
  • 11
  • 30
  • 52
  • A .DS_Store file is something that the Finder creates when you look at a folder's contents. It stores metadata about how you want to view that folder. It's not an iCloud thing and I don't know why iCloud cares about it. – Tom Harrington Aug 02 '15 at 23:24
  • I also watched this post with similar problem http://stackoverflow.com/questions/27330282/pfubiquity-error-when-using-core-data-and-icloud. but i think there is no solution. This error is giving me a headache O_o' – user3065901 Aug 03 '15 at 08:26
  • I have a question about the 2 folders I have in my iCloud (1 with my name (mac) and one with mobile simulator). In one folder the transaction logs of my application for Mac are saved and in the other simulator logs. I think this logs are not sharing between them. These logs should be shared in the same folder? – user3065901 Aug 03 '15 at 12:00
  • Have a look at this: http://stackoverflow.com/questions/18015978/how-to-stop-creating-ds-store-on-mac The .DS_Store file is not necessary. – mirap Aug 03 '15 at 14:24
  • Thx for the info, but what about the transaction logs that are not being replicated between my mac app and my ios app? – user3065901 Aug 04 '15 at 06:41
  • If you have a .DS_Store file floating around its probably because you used Finder to look at one of your iCloud directories - use terminal if you want to see a file listing. I have some issues with this once upon a time. – Duncan Groenewald Aug 07 '15 at 12:43
  • What versions of OSX/iOS are you using? There have been some sync issues with the new beta's - I have a bug report for one which Apple have acknowledged. If you are using iOS8 and 10.10 then make sure you are correctly creating your iCloud containers in the iOS and OSX apps. I have some sample apps online (iOS and OSX apps that sync fine). Download then and check they work properly and then use them to verify your code. – Duncan Groenewald Aug 07 '15 at 12:45
  • Oh and don't forget to trigger the Simulators iCloud sync - its a Debug menu option as I recall. – Duncan Groenewald Aug 07 '15 at 12:49
  • It could be a bug. Please also take a look at https://forums.developer.apple.com/message/35551 for related information. – Rafael Bugajewski Aug 22 '15 at 20:03

0 Answers0