gpt4 book ai didi

iOS 核心蓝牙 : Advertised service is not discovered on peripheral

转载 作者:可可西里 更新时间:2023-11-01 04:57:25 25 4
gpt4 key购买 nike

连接到广播我感兴趣的特定服务的 BLE 设备后,为了发现此服务,我正在调用:

[self.peripheral discoverServices:@[[self.class serviceUUID]]];

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error 委托(delegate)方法被调用且没有错误,但为外围设备返回的服务数量为 0,并且因此没有进一步发现特征。有谁知道为什么会这样?提前致谢!

下面是委托(delegate)方法的完整主体。

- (void)peripheral:(CBPeripheral *)peripheral didDiscoverServices:(NSError *)error {
if (error) {
NSLog(@"didDiscoverServices failed: %@", error);
return;
}

NSLog(@"didDiscoverServices succeeded for peripheral: %@.", peripheral.name);
NSLog(@"Number of services: %d", peripheral.services.count);

for (CBService *s in peripheral.services) {
NSLog (@"Discovered service UUID: %@", s.UUID);
if ([s.UUID isEqual:[self.class serviceUUID]]) {
NSLog(@"Discover characteristics...");
[self.peripheral discoverCharacteristics:@[[self.class controlPointCharacteristicUUID], [self.class packetCharacteristicUUID]] forService:s];
}
}
}

控制台显示:

2014-11-27 15:54:51.933 k[197:13362] didDiscoverServices succeeded for peripheral: BootK
2014-11-27 15:54:51.934 k[197:13362] Number of services: 0

最佳答案

我唯一能想到的是 [self.class serviceUUID] 与您要查找的服务的 UUID 不匹配。启动扫描时,是否按服务 UUID 进行过滤?

[self.centralManager scanForPeripheralsWithServices:[self.class serviceUUID] options:nil];

如果没有,这可能可以解释为什么您能够发现并连接到它,但不能发现该特定服务。

关于iOS 核心蓝牙 : Advertised service is not discovered on peripheral,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27172556/

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