How to populate an empty CoreData database from remote Simperium store?

171 Views Asked by At

I'm running the SimpletodoFinal.xcodeproj included with the Simperium samples. The sample works fine, and I can see items synced between the iOS simulator and the web app connected to Simperium's data store.

I add a few items and ensure changes are sync'd. Then I quit the iOS app and remove the app's sqlite database and start the app again. This would seem to be the use case when an existing user brings a new device online.

The problem I'm having is that the app is empty. The remote data is not synced down to populate the new database. Anyone know why this might be? Do I somehow need to trigger a manual sync on startup?

Thank you.

2

There are 2 best solutions below

3
On BEST ANSWER

Nuking the sqlite store alone might cause issues, since Simperium also relies on a couple metadata stores to determine the current sync status.

Please, try calling the method [simperium signOutAndRemoveLocalData:YES] instead, that is the preferred way of deleting everything.

0
On

The reason remote changes weren't downloaded is that the client thought it was up-to-date. There was an entry in the preferences file (/Library/Preferences/com.codality.SimpletodoFinal.plist) like this:

lastChangeSignature-Todo : 52a22dc4ba5fdc4e28e0fa8a

I'm assuming Simperium interpreted that entry to mean that the latest change had already been incorporated into the database. Thus, there was nothing new to download.

Because there was stale data in the preferences file, my experiment was not an accurate representation of a user bringing on a new device.

I closed the app, removed the database again, and removed the above entry in the prefs file. Then I re-ran the app and sure enough, all remote data was correctly downloaded.