-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Local Store vs iCloud Store -> Merging/Backup #4
Comments
Hi, Duplicates will occur if you migrate back and forth, since CoreData doesn't know that record A in your local store is the same as record A in the iCloud store, so if you migrate back from iCloud to local, you'll get two copies of record A. How you de-duplicate depends on your data model. To answer your last question, you can't determine the stages between "Using local storage: 1" and "Using local storage: 0" in any way that's of much use. You can get the notifications of all the internal store changes that Core Data is doing behind the scenes for you, but it's very tricky to be able to act on them in any reliable way, and they're a Core Data implementation detail which could easily change in future iOS versions so you can't depend on them. It would be very helpful if there were an official way to get more information about what was going on. |
Hi, thank you for your message. It really was easy for me (still as a rookie) to implement iCloud functionality to my App with your code. I think merging is one of the most difficult tasks in syncing. As far as I can see also in various other services this fails quite often. I will choose one of two options: 1) no merging and confront/explain the user this missing option or 2) I will import everything and will mark the "new" data somehow so the user can edit it by himself. It is a small data model so 2) could be possible. With persistentStoreDidImportUbiquitousContentChanges I am able to detect changes to the store and act accordingly. But my concern is, when I add a new device (fresh install of the App) to my "iCloud chain" I will have to be notified if the iCloud store is used. This could take a while and I want to show the user some kind of a initial loading screen. Is this possible? |
I have exactly the same problem in my apps. There is a period of time between the user enabling iCloud and the data syncing from the cloud (the time between "Using local storage: 1" and "Using local storage: 0" where nothing appears to be happening. As far as I know there is no way to be notified of what's going on behind the scenes in a reliable way, so it's not possible to show a "loading" screen because you won't know when to get rid of it. It's very annoying. |
I figured out a way to do that (but it shows some magic) and I hope I can explain it correctly (and I made a screen cast, see below) For testing, I designed the UI with a hidden TableView and a spinner in the navigation bar. In the view.m I placed a function where I set the hidden attribute to FALSE and the spinner to stopAnimation besides other things like updating the TableView etc. I put a notification in What happens:
now the magic happens: I made a screen cast: It seems to me that the TableView somehow magically updates after the iCloud sync even though I told in the code to show the tableview immediately. I expected that the table view would be presented empty... I wonder, what the magic part is :) Peter BTW: Hope you have had a good xmas. |
Thanks! That's very useful information! I have noticed similar "magic" in my app. On a I'm going to implement your trick in an update yo my app, definitely makes it much nicer for the user. Thanks again! PS: Hope you had a great xmas too :-) |
Hi Michael, Can you give an example of the Is it the ubiquityContainerURL? |
Hi awadhawan, For migrating local to iCloud (assuming you do this somewhere in PersistentStack.m): __weak NSPersistentStoreCoordinator *psc = self.managedObjectContext.persistentStoreCoordinator;
NSPersistentStore *currentStore = [psc persistentStores][0];
[psc migratePersistentStore:currentStore
toURL:self.storeURL
options:@{ NSPersistentStoreUbiquitousContentNameKey : @"iCloudStore" }
withType:NSSQLiteStoreType
error:&error]; For migrating iCloud to local: __weak NSPersistentStoreCoordinator *psc = self.managedObjectContext.persistentStoreCoordinator;
NSPersistentStore *currentStore = [psc persistentStores][0];
[psc migratePersistentStore:currentStore
toURL:self.storeURL
options:@{ NSPersistentStoreRemoveUbiquitousMetadataOption : @YES }
withType:NSSQLiteStoreType
error:&error]; The Also, take a look at this example from objc.io. Michael. |
Thanks a lot Michael. That makes it much simpler to understand since I was wondering how the "switch" would work in regards to turning iCloud on/off. Excellent work with "PersistantStack". Helped a lot with understanding the simplicity involved in using iCloud with iOS 7. |
First of all: Thank you so much for showing me how "easy" it is now to implement iCloud.
I know, that this stack is not a full implementation, but perhaps I can ask two things I see not clear.
If I understand it right, the data of a local store and the iCloud store is totally different. Meaning: By "switching" from a local to an iCloud store or back, I have to create the code for the migration/backup, right? In my case it is a very tiny data model with two very basic entities. So, when the user decides to switch off from iCloud for this App in settings, then he will loose the data as long as I did not implement merge/backup or he switches back to iCloud, correct?
Another thing: How can I determine the stages between "Using local storage: 1" and "Using local storage: 0"? I think, this is also important.
Perhaps you will find time and drop me a line. And again, thanks for the Stack!
The text was updated successfully, but these errors were encountered: