GLOBAL_QUEUE_PRIORITY_DEFAULT停止UI响应

时间:2017-04-25 05:21:52

标签: ios

我正在与GLOBAL_QUEUE_PRIORITY_HIGH的MQTT进行连接。它是否正确?因为我的UI需要时间来回应。

dispatch_async(dispatch_get_global_queue(GLOBAL_QUEUE_PRIORITY_HIGH,0),{
   guard self.session != nil  else {
        fatalError("Could not create MQTTSession")
    }


    let transportSocket:MQTTCFSocketTransport = MQTTCFSocketTransport ()
    transportSocket.host = MQTT_HOST;
    transportSocket.port = MQTT_PORT;


    self.session!.transport = transportSocket


    self.session!.delegate = self
    self.session!.userName = token
    self.session!.password = userId
    self.session!.keepAliveInterval = 300
    self.session!.cleanSessionFlag = false
    self.connect()
})

我想将它与主线程分开。这就是我做这件事的原因。请告诉我这是否正确。

1 个答案:

答案 0 :(得分:0)

您将使用main方法编写 GLOBAL_QUEUE_PRIORITY_HIGH。

dispatch_async(dispatch_get_global_queue(GLOBAL_QUEUE_PRIORITY_HIGH,0),{
// Here you can call methods like getting data from database or from server.

//注意:不要尝试任何UI更新,有时可能会崩溃你是应用程序。         dispatch_async(dispatch_get_main_queue(){

       // Here you can write for update UI.

     })
})