iOS - CoreBluetooth didDiscoverPeripheral不被称为

iOS - CoreBluetooth didDiscoverPeripheral不被称为

问题描述:

我已经在Xcode 6中制作了一个非常简单的iOS应用程序来试用CoreBluetooth并与我的Polar H6心率监视器进行通信。出于某种原因,didDiscoverPeripheral方法未被调用。iOS - CoreBluetooth didDiscoverPeripheral不被称为

我发现在计算器上类似如下的问题,但你要么是有点不同,或者真的不回答这个问题对我来说:

我的codeD viewLidLoad:

NSArray *services = @[[CBUUID UUIDWithString:HRM_HEART_RATE_SERVICE_UUID]]; 
CBCentralManager *centralManager = [[CBCentralManager alloc] initWithDelegate:self queue:nil]; 
[centralManager scanForPeripheralsWithServices:services options:nil]; 
self.centralManager = centralManager; 

方法centralManagerDidUpdateState正在被调用,它告诉我状态等于CBCentralManagerStatePoweredOndidDiscoverPeripheral方法永远不会被调用,即使我将nil转换为scanForPeripheralsWithServices方法。

在app store中,我已经下载了一个名为LightBlue的应用程序。它是一个非常简单的应用程序来测试任何使用蓝牙4.0 LowEnergy的设备。它扫描外围设备并显示有关设备及其服务的详细信息。 LightBlue应用程序看到我的HeartRate显示器,而我自己的小应用程序没有。

有没有人有任何提示或线索如何前进?

(我使用的Xcode 6和iPhone 6与iOS 8)

+0

的[iOS 8的核心蓝牙未发现外设]可能重复(http://*.com/questions/25586527/ios-8-core-bluetooth-not-discovering-peripherals) – Paulw11 2014-10-19 19:33:38

+0

@ Paulw11谢谢!这确实是一个相同的问题(我自己没有找到它的耻辱),它给了我解决方案! – Brabbeldas 2014-10-20 08:42:10

+0

请检查此解决方案:http://*.com/questions/28167804/why-use-corebluetooth-connectperipheral-did-not-call-delegate-methods-in-ios8/31961410#31961410 – oOEric 2015-08-12 09:38:44

我用的雨燕,它看起来像蓝牙队列必须使用主队列

myCentralManager = CBCentralManager(delegate: self, queue: dispatch_get_main_queue()) 

这是在目标C

myCentralManager = [[CBCentralManager alloc] 
    initWithDelegate:self queue:dispatch_get_main_queue()];