I have managed to work through this but it is a classic case of trying so many different things and running into so many brick walls that I no longer remember exactly what I did that cured the problem, much less why I had the problem in the first place. Maybe I can share a couple things that I came across.
One is a blog at http://blog.wadetregaskis.com/icloud-documentation-is-crap/. This paragraph explains how NSMetadatQuery
really works:
[This] explains something crucial about NSMetadataQuery: Long story short, NSMetadataQueryDidUpdateNotification
does not do what you might expect. Certainly not what I expected. I read the documentation as saying that it would be used to deliver results, and NSMetadataQueryDidFinishGatheringNotification
would be posted when the full first pass had completed. That’s a very typical pattern used elsewhere in Apple’s APIs (including Spotlight, so one would assume NSMetadataQuery
would work the same). But it doesn’t.
Instead, all of the first full run’s results are buffered up and provided by NSMetadataQueryDidFinishGatheringNotification
. NSMetadataQueryDidUpdateNotification
is purely for subsequent, real-time changes.
Another thing that I think may have been causing me problems is that I may have had more than one instance of NSMetadataQuery active at the same time. I'm not sure and I don't know why that would prevent either of them from sending an update notification.
At any rate the following code now works for me:
if (usingIcloud) {
if (query) [query disableUpdates];
query.predicate = [NSPredicate predicateWithFormat:@"%K like '*.caf' or %K like '*.mov'", NSMetadataItemFSNameKey, NSMetadataItemFSNameKey];
query.searchScopes = [NSArray arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(updateUbiquitousDocuments:)
name:NSMetadataQueryDidFinishGatheringNotification
object:nil];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(updateUbiquitousProgress:)
name:NSMetadataQueryDidUpdateNotification
object:nil];
[query enableUpdates];
}
I am able to get updates which tell me how much of a given file has downloaded in my updateUbiquitousProgress method and let it run a progress bar. If anyone wants to know more or see more of the code that ended up working, I'd be happy to oblige.