6

對於iCloud的插件,我寫,我訂閱我的iCloud管理器類這些iCloud的NSMetaDataQuery觀察員:NSMetaDataQuery從來不打電話回來NSMetadataQueryDidFinishGatheringNotification

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

的問題是,沒有這些選擇實際上是不斷被召回,甚至沒有,我特別需要NSMetaDataQueryDidUpdateNotification來跟蹤雲中文件的上傳/下載進度。

有一件奇怪的事情是,我前些天有這樣的工作,但不知何故它剛剛停止工作,並且我試圖弄清楚問題實際上是什麼都不知情。通過下注到NSMetadataQueryDidStartGettingNotification我可以看到它確實啓動,但它就像它永遠不會結束。這很奇怪。

我想知道是否有人有任何線索,因爲上述代碼會出現什麼問題?或者我可以在哪裏找到問題。

感謝您的時間:)

+0

你有沒有發現這有什麼問題?我很想回答。 – OlivaresF

+0

不幸的是,我從來沒有發現這是什麼原因。我找不到任何其他地方在線任何解釋:(仍然會愛上一個答案 – CodingBeagle

+0

你想要搜索的所有文件的列表嗎?你有沒有試過讓filepattern是一個單一的文件類型,如.txt? – OlivaresF

回答

16

確保你在主線程啓動NSMetadataQuery。那時這個要求沒有記錄。

+0

那麼這是令人沮喪的感謝張貼這 –

+2

現在記錄下'startQuery' –

+0

它被記錄,你必須在主隊列或與NSMetadataQuery相關的隊列啓動它 – Andy

1

這是挖掘的祕密。我不知道你現在是否已經放棄了,但最後我可能會有所幫助。

事實證明,對於某些(所有?)C++應用程序配置,有一個消息泵不會自動運行。在我的應用程序,我終於開始得到我預期的回調放置一個循環像這樣跟着我[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** }
在回調是設置正確地更新m_state變量。

我的例子只是阻塞,使用它自己的線程時間片來運行循環(除非被達到超時中斷),但是這也可以以異步方式設置。

另一件事要注意那些誰太過火遺留支持:
此方法導致應用程序啓動在OS X 10.9及以上泄漏馬赫端口。儘管如此,還沒有看到任何新問題。

相關問題