NSMetaDataQuery will never call back with NSMetadataQueryDidFinishGatheringNotification

For the iCloud plugin I'm writing, I sign my iCloud manager class to these iCloud NSMetaDataQuery watchers:

// Add a predicate for finding the documents NSString* filePattern = [NSString stringWithFormat:@"*.%@", @"*"]; self.metadataQuery = [[NSMetadataQuery alloc] init]; // Before starting to query, it is required to set the search scope. arrayWithObject:NSMetadataQueryUbiquitousDocumentsScope]]; // It is also required to set a search predicate. [self.metadataQuery setPredicate:[NSPredicate predicateWithFormat:@"%K LIKE %@", NSMetadataItemFSNameKey, filePattern]]; // Listen for the second phase live-updating [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryDidReceiveNotification:) name:NSMetadataQueryDidUpdateNotification object:nil]; // Listen for the first phase gathering [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(queryIsDoneGathering:) name:NSMetadataQueryDidFinishGatheringNotification object:nil]; [self.metadataQuery startQuery]; 

The problem is that none of these selectors actually ever gets called back, not even once, and I especially need NSMetaDataQueryDidUpdateNotification to track the process of uploading / downloading files in the cloud.

It is strange that I worked on it the other day, but for some reason he simply stopped working, and I removed my blind position, trying to understand what the problem was. By subscribing to NSMetadataQueryDidStartGatheringNotification, I see that it begins, but it never ends. This is pretty weird.

I was wondering if anyone has any clue how to deal with this code? Or where else can I find the problem.

Thank you for your time:)

+6
source share
2 answers

Make sure you run NSMetadataQuery in the main thread. Then this requirement was not documented.

+16
source

It was a secret to dig up. I don’t know if you have let go now, but finally I could help.

It turns out that for some (all?) C ++ application configurations there is a message pump that does not start automatically. In my application, I finally started getting the expected callbacks after placing the loop following my call [m_query startQuery] :
// make it look syncronous for now while( m_state != finished ) { Check_For_Interruption(); [[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:timeslice]]; //<--**this line is the key** }
where the callbacks are configured to correctly update the m_state variable.

My example simply blocks, using its own time stream to start the loop (if it is not interrupted by a timeout), but this can also be configured asynchronously.

One more thing that should be noted for those who are overboard on outdated support:
This method caused the application to bypass machine ports in OS X 10.9 and later. However, there were no problems with anything but this.

+1
source

All Articles