【发布时间】:2014-12-14 16:05:32
【问题描述】:
我在 Xcode 6 中制作了一个非常简单的 iOS 应用程序来试用 CoreBluetooth 并与我的 Polar H6 心率监测器进行通信。由于某种原因,没有调用 didDiscoverPeripheral 方法。
我在 StackOverflow 上发现了以下类似的问题,但你的问题要么有点不同,要么并没有真正为我回答:
- corebluetooth-diddiscoverperipheral-not-being-called-in-swift
- not-working-call-to-centralmanager-diddiscoverperipheral-advertisementdata
- diddiscoverperipheral-delegate-method-is-not-called
我在 viewDidLoad 中的代码:
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 被调用,它告诉我状态等于CBCentralManagerStatePoweredOn。
永远不会调用 didDiscoverPeripheral 方法,即使我将 nil 传递给 scanForPeripheralsWithServices 方法时也是如此。
在应用商店中,我下载了一个名为 LightBlue 的应用。它是一个非常简单的应用程序,可以测试任何使用蓝牙 4.0 LowEnergy 的设备。它扫描外围设备并显示有关设备及其服务的详细信息。 LightBlue 应用程序确实可以看到我的心率监测器,而我自己的小应用程序没有..
有没有人有任何提示或线索如何推进这个?
(我在 iOS 8 中使用 Xcode 6 和 iPhone 6)
【问题讨论】:
-
@Paulw11 谢谢!这确实是同一个问题(可惜我自己没有找到),它给了我解决方案!
标签: ios xcode ios8 bluetooth-lowenergy core-bluetooth