2014-04-15 34 views
3

當您在PFFile上調用getData時,如果isDataAvailable返回true,那麼這不應該導致執行阻塞操作,對不對?做類似isDataAvailable導致warnParseOperationOnMainThread()Parse.com

if (isDataAvailable) 
    [... getData]; 

Warning: A long-running Parse operation is being executed on the main thread.但我仍然得到警告:

我得到以下警告。

+0

這顯然是一些解析的API可以提高... – fatuhoku

回答

3

警告:長時間運行的Parse操作正在主線程上執行。

被髮送,因爲解析要警告你,你不應該執行繁重的操作,比如在主線程上獲取數據。這可能會導致UI複雜化,並且可能會因糟糕的用戶體驗而被拒絕。

您應該運行

[yourPFFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
    if (!error) { 
     // data available here, put any operations dependent on the data existing here 
    } 
    else { 
     // notify user that there was an error getting file, or handle error 
    } 
}]; 

有了這個,分析檢查,先來看看數據是否下載新數據之前可用。這樣你就可以避免在你的代碼中檢查isDataAvailable,並且如果有一個連接或一個大文件,它不會阻塞主線程。

+0

我怎麼會叫getDataInBackgroundWithBlock用零作爲塊? – Apollo

+1

你不會,你不應該。另一個選擇是使用'getDataInBackgroundWithTarget:selector:' – Logan

+0

如果你想在沒有塊的情況下在後臺運行,我很確定有一個'getDataInBackground'方法在沒有塊的情況下運行,但是你將沒有任何方法被通知您的所有數據都已收到。 – Logan

0

@Apollo 我該如何調用getDataInBackgroundWithBlock作爲塊的零?

使用

getDataInBackground() 

從PFFile代替

相關問題