When I tell a ubiquitous file to download, is there a way I can get notified when the download is complete?

If a file in iCloud hasn't been downloaded to the local iCloud container and I instruct it to download, is there a way for my app to get notified when the download is complete so I can copy the file, or would I have to just check to see if the file has been downloaded yet?

Accepted Reply

You can either use NSMetadataQuery. It allows to specify a searchScope and a predicate to filter search results. It provides one or more NSMetadataItem, which has various attributes, one of them is

NSMetadataUbiquitousItemDownloadingStatusKey


Or you can register for UIDocumentStateChangedNotification. Each time a notification is received you need to check with

[self.document.fileURL getResourceValue:&value forKey:NSURLUbiquitousItemDownloadingStatusKey error:&error]

wether file is still downloading or has finished.

Replies

You can either use NSMetadataQuery. It allows to specify a searchScope and a predicate to filter search results. It provides one or more NSMetadataItem, which has various attributes, one of them is

NSMetadataUbiquitousItemDownloadingStatusKey


Or you can register for UIDocumentStateChangedNotification. Each time a notification is received you need to check with

[self.document.fileURL getResourceValue:&value forKey:NSURLUbiquitousItemDownloadingStatusKey error:&error]

wether file is still downloading or has finished.