我正在尝试使用Apple 's ' BTLE Transfer ' sample project to understand CoreBluetooth programming. The app runs fine if I use an iOS 6 device as the Central, but if I run the same app with the iOS 7 device as the Central it doesn' t工作 . 外围设备在两个数据包之后停止发送,并且中心不接收其中任何一个数据包 .
唯一的线索就是这个警告,我只有在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外围设备通话时中断 .
2 回答
好吧,我刚刚在iOS 7外设的iOS 7中心运行它 . 如果您想要关于禁用重复过滤的警告消失,请在另一个线程上运行它 . 做这样的事情:
现在,它将允许您扫描并启用重复项 . 但是,您必须在主线程上调用textView setter才能设置文本而不会崩溃:
顺便说一句,您可能也想采用新的iOS 7委托初始化:
(只需检查iOS版本并调用相应的初始化方法)
在
scanForPeripheralsWithServices:options:
中,如果设置CBCentralManagerScanOptionAllowDuplicatesKey:@YES
,则将其更改为CBCentralManagerScanOptionAllowDuplicatesKey:@NO
,这意味着扫描应该在没有重复过滤的情况下运行 .对我来说,它也适用于iOS7 .