drewmccormack / ensembles

A synchronization framework for Core Data.
MIT License
1.63k stars 131 forks source link

Showing User when Sync is in progress #230

Closed RaymondMoay closed 8 years ago

RaymondMoay commented 8 years ago

Hi. I'm creating an app in swift and I'm using v1 of ensembles to sync. Currently everything works perfectly and I am able to tell the user when local files are merged with cloud data using persistentStoreEnsemble(didSaveMergeChangesWithNotification) delegate, however I would like users to know that syncing is in progress and I don't know how to proceed to do so.

Thanks!!

drewmccormack commented 8 years ago

Remember that your app is the one the calls leech and merge methods to start the syncs. So you know exactly when the sync starts, and can use the completion block to know when it ended. What you could do is fire a notification just before you call leech or merge, and another in the completion block.

To get percentage progress, I’m afraid you would need Ensembles 2. We added that more recently. (BTW Ensembles 2 is currently half price.)

Kind regards, Drew

On 24 Jun 2016, at 09:17, RaymondMoay notifications@github.com wrote:

Hi. I'm creating an app in swift and I'm using v1 of ensembles to sync. Currently everything works perfectly and I am able to tell the user when local files are merged with cloud data using persistentStoreEnsemble(didSaveMergeChangesWithNotification) delegate, however I would like users to know that syncing is in progress and I don't know how to proceed to do so.

Thanks!!

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/drewmccormack/ensembles/issues/230, or mute the thread https://github.com/notifications/unsubscribe/AAEuABOFXeULeNlWz4rn6QseZALOm05qks5qO4SZgaJpZM4I9hhR.

RaymondMoay commented 8 years ago

Thanks for the reply! I'm currently just testing ensembles and currently I like it and might be purchasing it soon since Core Data Sync is pretty much deprecated.

Anyhow, I have one more question.

In my CoreDataStack.swift:

func persistentStoreEnsemble(ensemble: CDEPersistentStoreEnsemble!, didSaveMergeChangesWithNotification notification: NSNotification!) { CoreDataStack.defaultStack.managedObjectContext.performBlockAndWait({ () -> Void in CoreDataStack.defaultStack.managedObjectContext.mergeChangesFromContextDidSaveNotification(notification) }) if notification != nil { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.02 * Double(NSEC_PER_MSEC))), dispatch_get_main_queue(), { NSLog("Database was updated from iCloud") CoreDataStack.defaultStack.saveContext() NSNotificationCenter.defaultCenter().postNotificationName("DB_UPDATED", object: nil) }) } }

This is called when merged occurred and I used it to stop an animation showing that syncing is still in progress. However, when the app is already updated, merging does not occur and no notification is fired, so I can't stop the syncing animation. Is there a way to know when data is already synced and no merge will occur so I can fire another notification telling the syncView to stop animating?

Sorry for the beginner questions, I'm new at programming.

drewmccormack commented 8 years ago

A better place to put the notification is in the completion block of the mergeWithCompletion: That always gets called.

Drew

On 27 Jun 2016, at 05:41, RaymondMoay notifications@github.com wrote:

Thanks for the reply! I'm currently just testing ensembles and currently I like it and might be purchasing it soon since Core Data Sync is pretty much deprecated.

Anyhow, I have one more question.

In my CoreDataStack.swift:

func persistentStoreEnsemble(ensemble: CDEPersistentStoreEnsemble!, didSaveMergeChangesWithNotification notification: NSNotification!) { CoreDataStack.defaultStack.managedObjectContext.performBlockAndWait({ () -> Void in CoreDataStack.defaultStack.managedObjectContext.mergeChangesFromContextDidSaveNotification(notification) }) if notification != nil { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, Int64(0.02 * Double(NSEC_PER_MSEC))), dispatch_get_main_queue(), { NSLog("Database was updated from iCloud") CoreDataStack.defaultStack.saveContext() NSNotificationCenter.defaultCenter().postNotificationName("DB_UPDATED", object: nil) }) } }

This is called when merged occurred and I used it to stop an animation showing that syncing is still in progress. However, when the app is already updated, merging does not occur and no notification is fired, so I can't stop the syncing animation. Is there a way to know when data is already synced and no merge will occur so I can fire another notification telling the syncView to stop animating?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/drewmccormack/ensembles/issues/230#issuecomment-228648048, or mute the thread https://github.com/notifications/unsubscribe/AAEuAC40KPKLko9b68kYWZrB1guCjO2Hks5qP0ZXgaJpZM4I9hhR.