Hi friend i have got NSMetaDataQuery results are blank and i analyzed this link. i am confused.Please help me, here i add my source code of meta query
- (NSMetadataQuery *)documentQuery {
NSMetadataQuery * query = [[NSMetadataQuery alloc] init];
if (query) {
// Search documents subdir only
[query setSearchScopes:[NSArray arrayWithObject:NSMetadataQueryUbiquitousDataScope]];
// Add a predicate for finding the documents
NSString * filePattern = [NSString stringWithFormat:@"*.%@", PTK_EXTENSION];
[query setPredicate:[NSPredicate predicateWithFormat:@"%K LIKE %@",
NSMetadataItemFSNameKey, filePattern]];
}
return query;
}
- (void)stopQuery {
if (_query) {
NSLog(@"No longer watching iCloud dir...");
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidFinishGatheringNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:NSMetadataQueryDidUpdateNotification object:nil];
[_query stopQuery];
_query = nil;
}
}
- (void)startQuery {
[self stopQuery];
NSLog(@"Starting to watch iCloud dir...");
_query = [self documentQuery];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(processiCloudFiles:)
name:NSMetadataQueryDidFinishGatheringNotification
object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(processiCloudFiles:)
name:NSMetadataQueryDidUpdateNotification
object:nil];
[_query startQuery];
}
- (void)processiCloudFiles:(NSNotification *)notification {
// Always disable updates while processing results
[_query disableUpdates];
[_iCloudURLs removeAllObjects];
// The query reports all files found, every time.
for (NSMetadataItem *result in _query.results) {
NSURL * fileURL = [result valueForAttribute:NSMetadataItemURLKey];
NSNumber * aBool = nil;
// Don't include hidden files
[fileURL getResourceValue:&aBool forKey:NSURLIsHiddenKey error:nil];
if (aBool && ![aBool boolValue]) {
[_iCloudURLs addObject:fileURL];
}
}
NSLog(@"Found iCloud URL: %@ .", _iCloudURLs);
NSLog(@"Found %d iCloud files.", _iCloudURLs.count);
_iCloudURLsReady = YES;
if ([self iCloudOn]) {
// Remove deleted files
// Iterate backwards because we need to remove items form the array
for (int i = _objects.count -1; i >= 0; --i) {
PTKEntry * entry = [_objects objectAtIndex:i];
if (![_iCloudURLs containsObject:entry.fileURL]) {
[self removeEntryWithURL:entry.fileURL];
}
}
// Add new files
for (NSURL * fileURL in _iCloudURLs) {
[self loadDocAtURL:fileURL];
}
self.navigationItem.rightBarButtonItem.enabled = YES;
}
if (_moveLocalToiCloud) {
_moveLocalToiCloud = NO;
[self localToiCloudImpl];
}
else if (_copyiCloudToLocal) {
_copyiCloudToLocal = NO;
[self iCloudToLocalImpl];
}
[_query enableUpdates];
}
please help me how can i solve this issue if i did wrong code please how can i approach correct way.