nothirst/TICoreDataSync

How to handle registration of two devices that have existing data.

Opened this issue · 4 comments

I'm adding TICoreDataSync to my app and want to make sure I understand correctly how to handle registering two devices that may have existing data.

I have an existing app that uses a Core Data database and does not having syncing. I 'm adding TICoreDataSync to enable syncing between devices. For simplicity, let's assume I want the data from both devices to be added.

Here is a flow diagram of the steps I was thinking of using to determine what to do when registering a new device.

prayer_notebook_dropbox_flow

Does that seem right? If a whole store has already been uploaded I can't just upload another whole store to get that data added, I have to download the existing store and then migrate the data over, correct?

If that is the case, then how do I ask TICoreDataSync if there is an existing whole store once I've registered the app and document managers?

Would it be simpler not to upload the existing store and just always manually add the entries from the existing database to the new synced database?

Does that seem right?

Yes, your diagram appears to be correct.

If a whole store has already been uploaded I can't just upload another whole store to get that data added, I have to download the existing store and then migrate the data over, correct?

Yes, this is also correct.

If that is the case, then how do I ask TICoreDataSync if there is an existing whole store once I've registered the app and document managers?

When doing sync setup in MoneyWell we ask the application sync manager for its previously synchronized documents (TICDSApplicationSyncManager::requestListOfPreviouslySynchronizedDocuments). If it comes back with a list of documents then we assume that whole stores have already been uploaded.

Would it be simpler not to upload the existing store and just always manually add the entries from the existing database to the new synced database?

I don't think that would be easier, no. I also don't know if TICDS would work that way... Your idea of merging the records into the existing whole store is probably the best, assuming you have a way to guarantee uniqueness.

Okay, thanks for the feedback and pointing me to requestListOfPreviouslySynchronizedDocuments. I think I have this flow working, so I'll try to come back here and explain what I did in case someone has this same question in the future.

Hi! Were you able to get this to work? My project does this currently - and if you like I can share that part of my code with you via a zip file. It's been working for about 3 months now.

@mazzuna I did get it to work and I'm shipping my first app with it next week. I'd be interested to see how you approached the problem if you want to share your code though. There was a bunch of code I had to write to try to handle iCloud failures and I still need to do some work around iCloud account switches.