gpt4 book ai didi

iphone - iOS 7 的 CBCentralManager 更改

转载 作者:可可西里 更新时间:2023-11-01 03:07:08 25 4
gpt4 key购买 nike

我正在尝试使用 Apple 的“BTLE Transfer” ' 了解 CoreBluetooth 编程的示例项目。如果我将 iOS 6 设备用作 Central,该应用程序运行良好,但如果我将 iOS 7 设备用作 Central,则它无法运行。外设在两个数据包后停止发送,中央设备没有收到任何一个数据包。

唯一的线索是我只在 iOS 7 上运行时收到的警告:

CoreBluetooth[WARNING] <CBCentralManager: 0x15654540> is disabling duplicate filtering, but is using the default queue (main thread) for delegate events

谁能告诉我需要更改哪些内容才能使此应用与 iOS 7 兼容?

编辑:当两个设备都是 iOS7 时没有问题。这只会在 iOS7 中心与 iOS6 外围设备通信时中断。

最佳答案

好吧,我只是在 iOS 6 外围设备的 iOS 7 中心运行它。如果你想让关于禁用重复过滤的警告消失,只需在不同的线程上运行它。做这样的事情:

dispatch_queue_t centralQueue = dispatch_queue_create("com.yo.mycentral", DISPATCH_QUEUE_SERIAL);// or however you want to create your dispatch_queue_t
_centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:centralQueue];

现在它将允许您在启用重复项的情况下进行扫描。但是,您必须在主线程上调用 textView setter 才能设置文本而不会崩溃:

dispatch_async(dispatch_get_main_queue(), ^{
[self.textview setText:[[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding]];
});

顺便说一句,您可能还想采用新的 iOS 7 委托(delegate)初始化:

_centralManager = [[CBCentralManager alloc]initWithDelegate:self queue:centralQueue options:nil];//set the restoration options if you want

(检查iOS版本并调用合适的初始化方法即可)

关于iphone - iOS 7 的 CBCentralManager 更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18970247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com