相反輪詢NSMetadataItem
更改的,你應該只聽從NSMetadataQuery
更新和獲取NSMetadataUbiquitousItemPercentDownloadedKey
一次(和更新UI)每次收到的更新時間。
(I 認爲現有的NSMetadataItem對象在下載過程中不會更新,除非從下載過渡到完全下載)。
這裏是聽使用KVO NSMetadataQuery更新的方式:
// To register for KVO updates:
[query addObserver:self
forKeyPath:@"results"
options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionOld
context:nil];
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
// check that "object" is your metadata query then:
NSUInteger changeKind = [[change objectForKey:NSKeyValueChangeKindKey] unsignedIntegerValue];
switch (changeKind) {
case NSKeyValueChangeSetting:
// The whole array of results changed, update your model accordingly
// ...
break;
case NSKeyValueChangeReplacement:
// This is where you update your progress bar in most cases
// Enumerate [change objectForKey:NSKeyValueChangeNewKey], this is a list of NSMetadataItems that will have all the desired properties
break;
case NSKeyValueChangeInsertion:
// Handle a new document
// ...
break;
case NSKeyValueChangeRemoval:
// Handle a removed document
// ...
break;
}
}
如果仍然看到沒有更新的進展,請提交錯誤報告與蘋果。
顯示您開發的代碼。 – Apurv