Результаты запроса iCloud NSMetadata пусты

Привет друг, у меня есть пустые результаты NSMetaDataQuery, и я проанализировал эту ссылку . я запутался. Пожалуйста, помогите мне, здесь я добавляю исходный код мета-запроса

- (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];

}

пожалуйста, помогите мне, как я могу решить эту проблему, если я сделал неправильный код, пожалуйста, как я могу подойти правильно.


person Vijay    schedule 19.02.2013    source источник