Hello all
I am having problems using NSMetadataQuery to check cloud states. Consider the code snippet below (originally inspired by the code posted in
NSMetadataQuery *query = [[NSMetadataQuery alloc] init];
void (^notificationBlock)(NSNotification __strong *notification) = ^(NSNotification __strong *notification) {
NSLog(@"entering notification block");
};
[query enableUpdates];
NSURL *url = [[[NSFileManager defaultManager] URLForUbiquityContainerIdentifier:nil] URLByAppendingPathComponent: @"Documents"];
NSPredicate *metadataPredicate = [NSPredicate predicateWithFormat:@"%K BEGINSWITH %@", NSMetadataItemPathKey, url.path];
query.notificationBatchingInterval = 1.0;
query.searchScopes = [NSArray arrayWithObject:NSMetadataQueryUbiquitousDataScope];
query.predicate = metadataPredicate;
NSOperationQueue* nsQueue = [NSOperationQueue new];
[[NSNotificationCenter defaultCenter]
addObserverForName:NSMetadataQueryDidFinishGatheringNotification
object:query
queue:nsQueue
usingBlock:notificationBlock
];
[query startQuery];
[NSThread sleepForTimeInterval: 1000.0f];
My expectation would be that the notification block gets called by another thread while the main thread is sleeping. Instead the block is never called. Any help is greatly appreciated.