isDataAvailable导致warnParseOperationOnMainThread()Parse.com

时间:2014-04-15 01:38:11

标签: ios objective-c parse-platform

当你在PFFile上调用getData时,如果isDataAvailable返回true,那么这不应该导致执行阻塞操作,对吗?

我在做

之类的事情时收到以下警告:Warning: A long-running Parse operation is being executed on the main thread.
if (isDataAvailable) 
   [... getData];

但我仍然收到警告。

2 个答案:

答案 0 :(得分:3)

  

警告:正在主线程上执行长时间运行的Parse操作。

发送

是因为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,如果有连接或大文件,它将不会阻止主线程。

答案 1 :(得分:0)

@Apollo 如何以块为零调用getDataInBackgroundWithBlock?

使用

getDataInBackground()
来自PFFile的