在我的SWIFT2.0的iOS应用程序中,我在后台线程中向服务器请求数据时,显示了一个自定义的微调函数。当我拿回数据并更新sqlite数据库时,旋转器就开始冻结(大约15秒来处理所有查询)。在XCode中,设备cpu的活跃度在95%到100%之间。我试着以不同的方式使用中央调度中心,但我不知道如何在不冻结微调器动画的情况下使其工作。你知道怎么解决这个问题吗?谢谢!!
我不能发布整个代码,但它类似于下面的代码:
//Using the spinner here https://github.com/icanzilb/SwiftSpinner
Spinner.show("Please wait", animated: true)
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0))
{
//around 5 seconds to get data
var data = getDataFromServer()
//around 20 sec to process and save the data in sqlite. It stops spinning from here..
saveDataInDB(data)
}
发布于 2016-09-20 16:16:39
我找到窃听器了。在saveDataInDB()中,我用OAuthSwift发出请求,它在接收回调时更改执行线程。它跳回到主线程上,然后db查询也在主线程上运行。我在这里为这个问题提出了一个新问题:OAuthSwift request callback on main thread
https://stackoverflow.com/questions/39527976
复制相似问题