Skip to content
Browse files

Added a property to the new TIUbiquityMonitor class that allows initi…

…ation of transfers to be toggled.
  • Loading branch information...
1 parent c925736 commit 600a4d6e39cf514b213c0d49004a80cc282f39e4 @drewmccormack committed Feb 14, 2013
View
2 TICoreDataSync/06 External Sources/TIUbiquityMonitor.h
@@ -24,6 +24,8 @@
@property (readonly) long long ubiquitousBytesToUpload, ubiquitousBytesToDownload;
@property (readonly) NSPredicate *predicate;
+@property (readwrite) BOOL initiateTransfers;
+@property (readonly) BOOL isMonitoring;
- (id)initWithPredicate:(NSPredicate *)predicate;
View
8 TICoreDataSync/06 External Sources/TIUbiquityMonitor.m
@@ -24,12 +24,13 @@ @implementation TIUbiquityMonitor {
NSMetadataQuery *metadataQuery;
NSMutableDictionary *downloadingBytesByURL, *uploadingBytesByURL;
void (^progressCallbackBlock)(long long toDownload, long long toUpload);
- BOOL isMonitoring;
}
@synthesize ubiquitousBytesToDownload = ubiquitousBytesToDownload;
@synthesize ubiquitousBytesToUpload = ubiquitousBytesToUpload;
@synthesize predicate = predictate;
+@synthesize initiateTransfers = initiateTransfers;
+@synthesize isMonitoring = isMonitoring;
#pragma mark Initialization and Deallocation
@@ -40,6 +41,7 @@ - (id)initWithPredicate:(NSPredicate *)newPredicate
predictate = [newPredicate retain];
progressCallbackBlock = NULL;
isMonitoring = NO;
+ initiateTransfers = NO;
metadataQuery = nil;
downloadingBytesByURL = uploadingBytesByURL = nil;
ubiquitousBytesToUpload = ubiquitousBytesToDownload = 0;
@@ -133,7 +135,7 @@ - (void)update:(NSNotification *)notif
// Start download
NSError *error = nil;
- if ( percentage == 0.0 && ![fileManager startDownloadingUbiquitousItemAtURL:url error:&error] ) NSLog(@"Failed to initiate download with error: %@", error);
+ if ( initiateTransfers && percentage == 0.0 && ![fileManager startDownloadingUbiquitousItemAtURL:url error:&error] ) NSLog(@"Failed to initiate download with error: %@", error);
}
else if ( uploaded && !uploaded.boolValue ) {
double percentage = percentUploaded ? percentUploaded.doubleValue : 100.0;
@@ -143,7 +145,7 @@ - (void)update:(NSNotification *)notif
// Force upload
NSError *error = nil;
- if ( percentage == 0.0 && ![fileManager startDownloadingUbiquitousItemAtURL:url error:&error] ) NSLog(@"Failed to initiate upload with error: %@", error);
+ if ( initiateTransfers && percentage == 0.0 && ![fileManager startDownloadingUbiquitousItemAtURL:url error:&error] ) NSLog(@"Failed to initiate upload with error: %@", error);
}
}

0 comments on commit 600a4d6

Please sign in to comment.
Something went wrong with that request. Please try again.