0
votes

I'm developing an app which uses iCloud to sync core data. I have a complex model. My problems are next: 1) [NSFileManager defaultManager] URLForUbiquityContainerIdentifier often returns nil url even if iCloud enabled on the device. I read it should call it in another thread. But I need to show views which use core data same time. Because this I thought to use second persistent store to store local data in it and when ubiquity store initialized - migrate to it; migration overwrites all data in store - this way not suitable. 2) Solution is to use seed stores as described here: iOS: Migrating existing Core Data-database into iCloud But I have complex model and it difficult to copy all objects from one store to another and it uses big memory amount.

Please give me advice in problem solution.

May be another way to sync core data. Dropbox is not accepted.

1
Check out Wasabi Sync.... its a 3rd party service. Disclosure: I have no personal ties to them, but I know of people who have used them before and I do know the author.logixologist

1 Answers

0
votes

1) You have not included any of the code you are using but I have never seen the following return nil when iCloud account is active and "Documents & Data" is enabled. Check you are calling it correctly and that you have the correct ID each time.

NSString *ubiquityID = @"com.company.AppName";
NSURL *iCloudURL = [[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:ubiquityID];

You don't need to call this on another thread (well I don't and its never been a problem).

With regard to using two stores, Core Data already does this if you set the iCloud options, it boots up using a local fallback store to give your app immediate access while it initialised the iCloud synced local store. Once this is done it switches the stores and sends a notification. So its not clear why you would want to create your own additional store.

2) I don't understand the problem you are trying to solve. If you need to load initial data into the store then either do so by reading from some input file when the store is first created or include a store in the app bundle and either migrate this store to iCloud when the app is run the first time or copy the data programatically to the new store. I would do the former because Core Data does all the work for you.