2

I am trying to integrate iCloud usage in my app. I did understand how the process works and its basis. I was already able to upload content to iCloud but I need to track down the uploading progress in order to improve the Ux that I am providing to the end user.

So, basically I upload the document using the method below:

- (void)saveToURL:(NSURL *)url forSaveOperation:(UIDocumentSaveOperation)saveOperation completionHandler:(void (^ __nullable)(BOOL success))completionHandler __TVOS_PROHIBITED;

Before I call this method, I am also initialising a MetadataQuery. This query is specific and it is supposed to get the progress of a document passing the document's name and its URL as parameters. Something like this:

- (void)startMonitoringMetadataQueryWithBackupName:(NSString *)backupName andBackupURL:(NSURL *)backupURL;

Method implementation:

enter image description here

After doing this, I am only receiving events triggered by NSMetadataQueryDidStartGatheringNotification and even so, the received info does not bring any usable value.

I was expecting to receive events from the NSMetadataQueryDidUpdateNotification, bringing the MetadataQuery with results in order to get the NSURLUbiquitousItemPercentUploadedKeyvalue. However, I am not receiving any notification of this type and I am not able to monitoring the upload progress.

Am I missing something? I am out of ideas because this seems so simple and it does not work as expected.

(Note: I also need to implement a similar behaviour when a document is downloaded and I think the approach will be the same, just changing the query's valueListAttributes. I am afraid this problem will persist when I am implementing it)

Thanks

Tiago Pereira
  • 592
  • 1
  • 4
  • 19
  • I have noticed that I have a problem when I was defining the predicate. I was using the wrong variable. However, I fixed the problem and the behaviour described is still verified (it still does not work). – Tiago Pereira Apr 28 '17 at 22:58
  • There is no such thing. iCloud sync through the network directly to other devices and to the iCloud server dependent on what's needed first. Therefor there is no way to monitor if the upload has been done or not. – I make my mark May 01 '17 at 09:15
  • So, you are saying that I do not have a way to monitor the upload progress? I saw a similar mechanism used by whatsapp when they want to make a backup. It is displayed a progress when the iCloud upload is running. – Tiago Pereira May 01 '17 at 19:39
  • @TiagoPereira, I am facing the exact same issue now while also noticing that WhatsApp is handing this pretty nicely. Did you find an answer? – Joshua Jun 20 '18 at 09:34
  • 1
    @Joshua Yes, I got a solution but this isn't as accurate as I thought and even wtsapp does not work as well as I expected. But basically you must define a `NSMetadataQuery` matching your needs and when the upload starts, you should subscribe four different events: `NSMetadataQueryDidStartGatheringNotification`, `NSMetadataQueryDidFinishGatheringNotification`, `NSMetadataQueryDidUpdateNotification`, `NSMetadataQueryGatheringProgressNotification`. For each event, you’ll receive a notification that contais the `NSMetadataQuery` with some values updated (progress, upload status, etc.). – Tiago Pereira Jun 21 '18 at 10:39
  • @TiagoPereira thank you for your answer. I already started implementing using NSMetadataQueryDidStartGatheringNotification and NSMetadataQueryDidUpdateNotification notifications with reasonable results, but I guess that using all 4 notifications will improve the UI even further. Thank you for this! – Joshua Jun 21 '18 at 14:35
  • 1
    @Joshua no problem mate. If you need some help ask me! – Tiago Pereira Jun 22 '18 at 14:40

0 Answers0