2014-04-15 33 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代替

相关问题