gpt4 book ai didi

iOS - CoreBluetooth didDiscoverPeripheral 未被调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:19:58 27 4
gpt4 key购买 nike

我在 Xcode 6 中制作了一个非常简单的 iOS 应用程序来试用 CoreBluetooth 并与我的 Polar H6 心率监测器通信。由于某种原因,没有调用 didDiscoverPeripheral 方法。

我在 StackOverflow 上发现了以下类似的问题,但它们要么有点不同,要么没有真正为我回答:

我在 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 应用程序确实可以看到我的心率监测器,而我自己的小应用程序却看不到..

有没有人有任何提示或线索如何推进这个?

(我正在使用 Xcode 6 和 iPhone 6 和 iOS 8)

最佳答案

我正在使用 Swift,看起来蓝牙队列需要使用主队列

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

在 objective-c 中

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

关于iOS - CoreBluetooth didDiscoverPeripheral 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26452691/

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