Skip to content

Instantly share code, notes, and snippets.

@chbeer
Created June 18, 2013 05:58
Show Gist options
  • Save chbeer/5802954 to your computer and use it in GitHub Desktop.
Save chbeer/5802954 to your computer and use it in GitHub Desktop.
Short example how I setup the synchronisation for iCloud sync with TICoreDataSync
- (void) registerSyncManager
{
if (self.applicationSyncManager) return;
TICDSLogVerbosity logVerbosity = [[NSUserDefaults standardUserDefaults] integerForKey:kIVTICDSLogVerbosity];
[TICDSLog setVerbosity:logVerbosity];
if (![self hasLocalDatabase]) {
[self setDownloadStoreAfterRegistering:YES];
}
TICDSiCloudBasedApplicationSyncManager *manager = [TICDSiCloudBasedApplicationSyncManager defaultApplicationSyncManager];
manager.shouldUseEncryption = NO;
self.applicationSyncManager = manager;
NSURL *iCloudLocation = self.cloudStoreURL;
NSAssert(iCloudLocation != nil, @"Must be able to determine iCloud location to run this example");
#ifdef DEBUG
NSLog(@"Using Sync Path: %@", iCloudLocation);
#endif
if (!_ubiquityMonitor) {
NSPredicate *newPredicate = [NSPredicate predicateWithFormat:@"(%K = FALSE OR %K = FALSE) AND NOT %K LIKE %@", NSMetadataUbiquitousItemIsDownloadedKey, NSMetadataUbiquitousItemIsUploadedKey, NSMetadataItemPathKey, @"*/ExternalResources/*"];
_ubiquityMonitor = [[TIUbiquityMonitor alloc] initWithPredicate:newPredicate];
_ubiquityMonitor.initiateTransfers = YES;
/*
[_ubiquityMonitor startMonitoringWithProgressBlock:^(long long bytesToDownload, double percentageDownloading, long long bytesToUpload, double percentageUploading) {
if (bytesToUpload > 0 || bytesToDownload > 0) {
NSLog(@">>> ubiquity bytesToDownload: %lld bytesToUpload: %lld", bytesToDownload, bytesToUpload);
}
}];
*/
}
[manager setApplicationContainingDirectoryLocation:iCloudLocation];
NSString *clientUuid = [[NSUserDefaults standardUserDefaults] stringForKey:kIVAppSyncClientUUID];
if( !clientUuid ) {
clientUuid = [TICDSUtilities uuidString];
[[NSUserDefaults standardUserDefaults] setValue:clientUuid forKey:kIVAppSyncClientUUID];
}
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(activityDidIncrease:) name:TICDSApplicationSyncManagerDidIncreaseActivityNotification object:manager];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(activityDidDecrease:) name:TICDSApplicationSyncManagerDidDecreaseActivityNotification object:manager];
[manager registerWithDelegate:self
globalAppIdentifier:kIVGlobalAppIdentifier
uniqueClientIdentifier:clientUuid
description:[self deviceDescription]
userInfo:[self ticdsUserInfo]];
}
@chbeer
Copy link
Author

chbeer commented Jun 18, 2013

Yes, exactly that. It's just SyncData in my case ;)

I can't remember exactly, but as far as I remember you need it to load all changed files directly on iOS as on iOS the iCloud data is lazyly loaded, AFAIK. It would be better to integrate that into the DocumentManager, though.

@agrigg
Copy link

agrigg commented Jun 18, 2013

Okay, so you're using the TIUbiquityMonitor to monitor when data changes in iCloud. Are you doing anything else with it in your App Delegate or does something need to be implemented in startMonitoringWithProgressBlock to tell TICDS to sync?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment