Closed AndrewHartAR closed 11 years ago
Good Question. same problem for me.
Can you explain what you mean by "the service is switched off"? Do you mean that you're disabling the sync framework or just disconnected from the internet?
For example, say my app has existing data, inputted before i set up TICoreDataSync. How do I get all of this existing data to be sync'd when I start TICoreDataSync?
If I'm following you correctly we actually ran into this same issue in MoneyWell. What you can do is configure your document and application sync managers on application launch so that they track any changes to the managed object context before the first sync is performed. Here are the two methods in our MWISyncController class for doing that:
- (void)configureDocumentSyncManager
{
if (self.documentSyncManagerConfigured) {
return;
}
[self configureApplicationSyncManager];
TICDSDropboxSDKBasedDocumentSyncManager *docSyncManager = [[TICDSDropboxSDKBasedDocumentSyncManager alloc] init];
[docSyncManager configureWithDelegate:self appSyncManager:[TICDSDropboxSDKBasedApplicationSyncManager defaultApplicationSyncManager] managedObjectContext:[DataUtilities managedObjectContext] documentIdentifier:[[NSUserDefaults standardUserDefaults] valueForKey:kTICDSDocumentIdentifier] description:[[NSUserDefaults standardUserDefaults] valueForKey:kTICDSDocumentDescription] userInfo:nil];
self.documentSyncManager = docSyncManager;
[docSyncManager release], docSyncManager = nil;
self.documentSyncManagerConfigured = YES;
}
- (void)configureApplicationSyncManager
{
if (self.applicationSyncManagerConfigured) {
return;
}
TICDSDropboxSDKBasedApplicationSyncManager *manager = [TICDSDropboxSDKBasedApplicationSyncManager defaultApplicationSyncManager];
NSString *clientUuid = [[NSUserDefaults standardUserDefaults] stringForKey:NTSSyncClientUUIDKey];
if (clientUuid == nil) {
clientUuid = [TICDSUtilities uuidString];
[[NSUserDefaults standardUserDefaults] setValue:clientUuid forKey:NTSSyncClientUUIDKey];
}
NSString *deviceDescription = [[UIDevice currentDevice] name];
[manager configureWithDelegate:self globalAppIdentifier:MWIGlobalAppSyncIdentifier uniqueClientIdentifier:clientUuid description:deviceDescription userInfo:nil];
self.applicationSyncManagerConfigured = YES;
}
The public method called by our app delegate on launch is -configureDocumentSyncManager.
What if I want to add TICoreDataSync into an app which is already in AppStore? I attempt to upgrade my app with new core data sync features, what to deal with the data created in previous version?
When you first set up syncing within your app you can choose to upload your entire data store via the TICDSDocumentSyncManagerDelegate method:
- (BOOL)documentSyncManagerShouldUploadWholeStoreAfterDocumentRegistration:(TICDSDocumentSyncManager *)aSyncManager
To sync my core data with Dropbox, I set it up as usual and then in the delegate method
documentSyncManagerDidFinishedRegistering
, I call[self documentSyncManager] initiateSynchronization
. On thedocumentSyncManagerDidFinishSynchronization
method I find out if it's the first time synchronizing, and if it is I call[self documentSyncManager] initiateDownloadOfWholeStore
.The problem is that if later on the service is switched off, and then a new item is added to the database, it isn't synchronized between devices. How can I get objects created when the service is not running to sync?