caiyue1993/IceCream

Sync Engine not syncing first time?

Opened this issue · 3 comments

Thanks for such a great repo.

I am having an issue. When the user first downloads the app, CloudKit doesn’t seem to sync. It syncs and UI updates the second time the user opens the app.

What should the logic be for when the user downloads the app for the first time? So that all the data is presented from the beginning.

Can’t seem to get it to work.

No, that should not be the case. Please check the example project for details. Everything works fine when first installed on the devices.

Or you could provide more info if problem still occurs.

Ok, I found the issue.
The objects successfully sync the first time the user launches the application, but there is no callback or notification letting the user know when objects successfully finished syncing.

Although, there is a callback that you can use when force pulling objects from cloudkit:

syncEngine?.pull(completionHandler: { (err) in
            NotificationCenter.default.post(name: .didSyncData, object: nil)
 })

This is only useful when the user is force pulling objects from cloudkit. What if user wants to start or stop syncing objects to data? This callback wouldn't help in that case.

Expected Behavior

  1. Application is set to -> Not Sync
  2. The user decides to sync data so he sets the application to -> Sync
  3. Sync Engine starts running and pulls or pushes objects based on the latest data on either local device or cloud kit.
  4. When the syncing finishes on the local side -> A Notification is posted, letting the user know that syncing is finished.
  5. The UI updates based on sync completion

Actual Behavior

  1. Application is set to -> Not Sync
  2. The user decides to sync data so he sets the application to -> Sync
  3. Sync Engine starts running but doesn't pull or push any existing data from either local device or cloudkit data.
  4. When the syncing finishes on the local side -> No notification is posted
  5. User has to restart the application to update UI to data changes

Idea:

NotificationCenter.default.post(name: .syncEngineDidFinishSyncing, object: nil)

By the way. You are doing a great job with this repo. I appreciate all your hard work! Thanks... 😎🚀

Hi @johnnyperdomo , thanks a lot for your clear steps and suggestions. I'll take this advice into consideration seriously. For the time being, you could set up the UI reacted to the local data(no notification needed just as the example project indicates).

Please keep an eye on the updates. Thanks again :)