正在主线程上执行长时间运行的操作.迅速

kar*_*eem 4 iphone ios parse-platform swift

在我的ProfileViewController我有一个查询,检索存储为PF文件的用户个人资料图片.

  var query = PFQuery(className:"Users")
    query.whereKeyExists("profilePicture")
    query.findObjectsInBackgroundWithBlock {
        (objects: [AnyObject]!, error: NSError!) -> Void in
        if error == nil {

            self.userNameLabel.text = PFUser.currentUser().username

            if let imageFile = PFUser.currentUser().objectForKey("profilePicture") as? PFFile {
                if let data = imageFile.getData() {
                    self.profPic.image = UIImage(data: data)
                }
            }

        }
        else {
            println("User has not profile picture")
        }
    }
Run Code Online (Sandbox Code Playgroud)

这是此视图中唯一的查询,我的应用程序主页中有另一个查询,其中包含所有用户的所有帖子.我得到的错误是A long-running operation is being executed on the main thread.跟着Break on warnBlockingOperationOnMainThread() to debug.

我不知道如何解决这个问题,特别是因为我需要做另一个查询来获取当前用户发布的配置文件.我应该使用除了以外的东西吗findObjectsInBackgroundWithBlock?谢谢.

dan*_*anh 5

警告来自Parse sdk.这部分:imageFile.getData()是同步的,Parse足以在使用任何阻塞调用时发出警告.有两种getDataInBackground......作为替代品. 在这里的文档中查看它们.