nothirst / TICoreDataSync

Automatic synchronization for Core Data apps, between any combination of Mac OS X and iOS: Mac to iPhone to iPad to iPod touch and back again.
https://github.com/nothirst/TICoreDataSync/wiki
807 stars 61 forks source link

[iCloud] How to pause/resume the auto-sync mechanism and keep generating sync change files? #56

Open xsown opened 11 years ago

xsown commented 11 years ago

I am using the iCloud branch of TICDS in my project. I found that the TICDSFileManagerBasedDocumentSyncManager has 2 methods [beginPollingRemoteStorageForChanges] and [stopPollingRemoteStorageForChanges], while the TICDSiCloudBasedDocumentSyncManager has only [enableAutomaticSynchronizationAfterChangesDetectedFromOtherClients]. I'm trying to provide a wifi-only sync feature, as the syncing mechanism will automaticlly paused when the network is switching to WWAN or completely shutdown (airplane mode, etc), but I want to preserve the app sync manager and doc sync manager configured to keep generating sync change files for future syncing. So the questions are:

  1. how can i stop the watching(polling) function on TICDSiCloudBasedDocumentSyncManager after calling [enableAutomaticSynchronizationAfterChangesDetectedFromOtherClients]?
  2. the [deregisterDocumentSyncManager] of TICDSDocumentSyncManager will set the documentIdentifier and many other properties to nil, so I should not call [registerConfiguredDocumentSyncManager] to re-register, right? Shall I configure the document sync manager again?

Thank you!

chbeer commented 11 years ago

The iCloud syncing is based on the file syncing mechanisms provided by iOS. You can't pause that one. The iCloud syncing works like the file syncing as it only produces files in a certain directory. Besides that it only uses the NSMetadataQuery (in TIUbiquityMonitor) for checking if files have changed and need to be loaded (only needed on iOS as iOS doesn't load files automatically).

So, TL;DR: you don't need to pause anything when using iCloud sync. You can however deactivate the TIUbiquityMonitor. (I am planing to include the functionality of that class into the TICDSiCloudDocumentManager).

xsown commented 11 years ago

Thanks for your reply :)

  1. I've searched the whole project and didn't find any class using or mentioning TIUbiquityMonitor except itself. 
  2. My thought to stop monitoring files is to save the network flow under WWAN for the user. I know I cannot prevent the files coming into the ubiquity container, but can I just leave them as placeholders there and do not start to download them immediately, until the network is switched to WIFI? If it isn't possible to do so, I'll remove the wifi-only sync feature.
chbeer commented 11 years ago

1.) Yes, you're right. It's currently not used by the iCloud classes. I start it in my app as soon as the sync starts. And also use it early on a new device with a special NSPredicate to priorize the download of the whole store.

My idea would be to merge the functionality of that class into the TICDSiCloudDocumentManager to replace the directory watcher and use the NSMetadataQuery to identify new files / changes.

2.) There is a switch burried deep down in the iCloud Settings -> Documents and Data that is called (something like) "Use mobile data" (my iPhone is German so I don't know the English name). Isn't that doing what you're thinking about?

xsown commented 11 years ago
  1. I know what I should do now, thank you!
  2. I've forgot that setting... ok it is acceptable :)