Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Ubiquity monitor class now actively uses the file manager to start do…

…wnloads/uploads when it comes across files that are not actively uploading or downloading.
  • Loading branch information...
commit c925736da6cf58d54055b2b9b3310bacd8ed0bea 1 parent 10c0e71
@drewmccormack authored
Showing with 9 additions and 0 deletions.
  1. +9 −0 TICoreDataSync/06 External Sources/TIUbiquityMonitor.m
View
9 TICoreDataSync/06 External Sources/TIUbiquityMonitor.m
@@ -106,6 +106,7 @@ - (void)update:(NSNotification *)notif
{
[metadataQuery disableUpdates];
+ NSFileManager *fileManager = [[[NSFileManager alloc] init] autorelease];
NSUInteger count = [metadataQuery resultCount];
for ( NSUInteger i = 0; i < count; i++ ) {
NSURL *url = [metadataQuery valueOfAttribute:NSMetadataItemURLKey forResultAtIndex:i];
@@ -129,12 +130,20 @@ - (void)update:(NSNotification *)notif
long long fileDownloadSize = percentage / 100.0 * fileSize;
ubiquitousBytesToDownload += fileDownloadSize;
downloadingBytesByURL[url] = @(fileDownloadSize);
+
+ // Start download
+ NSError *error = nil;
+ if ( 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;
long long fileDownloadSize = percentage / 100.0 * fileSize;
ubiquitousBytesToUpload += fileDownloadSize;
uploadingBytesByURL[url] = @(fileDownloadSize);
+
+ // Force upload
+ NSError *error = nil;
+ if ( percentage == 0.0 && ![fileManager startDownloadingUbiquitousItemAtURL:url error:&error] ) NSLog(@"Failed to initiate upload with error: %@", error);
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.