Skip to content

Commit

Permalink
Added a property to the new TIUbiquityMonitor class that allows initi…
Browse files Browse the repository at this point in the history
…ation of transfers to be toggled.
  • Loading branch information
drewmccormack committed Feb 14, 2013
1 parent c925736 commit 600a4d6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions TICoreDataSync/06 External Sources/TIUbiquityMonitor.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@


@property (readonly) long long ubiquitousBytesToUpload, ubiquitousBytesToDownload; @property (readonly) long long ubiquitousBytesToUpload, ubiquitousBytesToDownload;
@property (readonly) NSPredicate *predicate; @property (readonly) NSPredicate *predicate;
@property (readwrite) BOOL initiateTransfers;
@property (readonly) BOOL isMonitoring;


- (id)initWithPredicate:(NSPredicate *)predicate; - (id)initWithPredicate:(NSPredicate *)predicate;


Expand Down
8 changes: 5 additions & 3 deletions TICoreDataSync/06 External Sources/TIUbiquityMonitor.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ @implementation TIUbiquityMonitor {
NSMetadataQuery *metadataQuery; NSMetadataQuery *metadataQuery;
NSMutableDictionary *downloadingBytesByURL, *uploadingBytesByURL; NSMutableDictionary *downloadingBytesByURL, *uploadingBytesByURL;
void (^progressCallbackBlock)(long long toDownload, long long toUpload); void (^progressCallbackBlock)(long long toDownload, long long toUpload);
BOOL isMonitoring;
} }


@synthesize ubiquitousBytesToDownload = ubiquitousBytesToDownload; @synthesize ubiquitousBytesToDownload = ubiquitousBytesToDownload;
@synthesize ubiquitousBytesToUpload = ubiquitousBytesToUpload; @synthesize ubiquitousBytesToUpload = ubiquitousBytesToUpload;
@synthesize predicate = predictate; @synthesize predicate = predictate;
@synthesize initiateTransfers = initiateTransfers;
@synthesize isMonitoring = isMonitoring;


#pragma mark Initialization and Deallocation #pragma mark Initialization and Deallocation


Expand All @@ -40,6 +41,7 @@ - (id)initWithPredicate:(NSPredicate *)newPredicate
predictate = [newPredicate retain]; predictate = [newPredicate retain];
progressCallbackBlock = NULL; progressCallbackBlock = NULL;
isMonitoring = NO; isMonitoring = NO;
initiateTransfers = NO;
metadataQuery = nil; metadataQuery = nil;
downloadingBytesByURL = uploadingBytesByURL = nil; downloadingBytesByURL = uploadingBytesByURL = nil;
ubiquitousBytesToUpload = ubiquitousBytesToDownload = 0; ubiquitousBytesToUpload = ubiquitousBytesToDownload = 0;
Expand Down Expand Up @@ -133,7 +135,7 @@ - (void)update:(NSNotification *)notif


// Start download // Start download
NSError *error = nil; 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 ) { else if ( uploaded && !uploaded.boolValue ) {
double percentage = percentUploaded ? percentUploaded.doubleValue : 100.0; double percentage = percentUploaded ? percentUploaded.doubleValue : 100.0;
Expand All @@ -143,7 +145,7 @@ - (void)update:(NSNotification *)notif


// Force upload // Force upload
NSError *error = nil; 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);
} }
} }


Expand Down

0 comments on commit 600a4d6

Please sign in to comment.