iphone - iOS 7 的 CBCentralManager 更改

标签 iphone ios bluetooth ios7 core-bluetooth

我正在尝试使用 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/

相关文章:

iphone - 我正在尝试初始化要推送的 UIViewController

android - 断开Android中的蓝牙 socket

android - Worklight API 中是否有任何应用程序间通信设施?

java - Android - 连接到蓝牙模块

java - 运行时异常 : "Stub!" without any other information

iPad 上的 iPhone 应用程序 : UILabel pixelated during rotation?

iphone - iPhone 的 XCode 测试自动化

iphone - CSS3 简化 Mobile Safari

iphone - 串联添加和删除 subview

iOS 图表额外空间和添加 x 轴标签