我想了解我的应用中发生的事情。单击此按钮一次并使用单例类BLEmanager建立连接时,它将连接并相应地工作。当设备未连接,不支持或未知时,UI会通知用户该问题。
当我再次尝试启用适配器时,它会跳过dispatch_async块并且不会更新UI。不知道为什么它第二次没有运行块,可能是我锁定线程。
- (IBAction)connectAdapter:(id)sender {
// connnect to adapter
dispatch_queue_t myQueue = dispatch_queue_create("my queue", NULL);
dispatch_async(myQueue, ^{
[BLEManager sharedInstance];
NSLog(@"DID RUN BLE MANAGER");
_adapter = BLEManager.sharedInstance.adapter;
_transporter = BLEManager.sharedInstance.transporter;
dispatch_async(dispatch_get_main_queue(), ^{
//update your UI
if (adapterState == adapterConnected){
//do stuff like request information and then dismiss an alert controller
}
});
});
}