iOS UI 微调器在处理后台线程时冻结
iOS UI spinner freeze while processing background thread
在 Swift 2.0 中我的 iOS 应用程序中,我在后台线程中请求来自服务器的数据时显示自定义微调器动画。
一旦我取回数据并更新 sqlite 数据库(大约 15 秒来处理所有查询),微调器就开始冻结。在 XCode 中,设备 cpu 显示 activity 在 95% 到 100% 之间。
我尝试以不同的方式使用 GRAND CENTRAL DISPATCH,但我没有找到如何在不冻结微调器动画的情况下使其工作。
知道如何解决这个问题吗?
谢谢!!
我无法 post 整个代码,但它与此类似:
//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)
}
我发现了错误。在 saveDataInDB() 中,我正在使用 OAuthSwift 请求在接收到回调时更改执行线程。它跳回主线程,然后数据库查询 运行 也在主线程上查询。我在这里为这个问题开了一个新问题:OAuthSwift request callback on main thread
在 Swift 2.0 中我的 iOS 应用程序中,我在后台线程中请求来自服务器的数据时显示自定义微调器动画。 一旦我取回数据并更新 sqlite 数据库(大约 15 秒来处理所有查询),微调器就开始冻结。在 XCode 中,设备 cpu 显示 activity 在 95% 到 100% 之间。 我尝试以不同的方式使用 GRAND CENTRAL DISPATCH,但我没有找到如何在不冻结微调器动画的情况下使其工作。 知道如何解决这个问题吗? 谢谢!!
我无法 post 整个代码,但它与此类似:
//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)
}
我发现了错误。在 saveDataInDB() 中,我正在使用 OAuthSwift 请求在接收到回调时更改执行线程。它跳回主线程,然后数据库查询 运行 也在主线程上查询。我在这里为这个问题开了一个新问题:OAuthSwift request callback on main thread