扫描特定服务CBUUID时找不到外围设备 [英] Cannot find peripheral when scanning for specific service CBUUID

查看:109
本文介绍了扫描特定服务CBUUID时找不到外围设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用时:

CBUUID * uuid = [CBUUID UUIDWithString:@"1800"]; // GAP
DEBUG_LOG(@"CBUUID: %@",uuid); // CBUUID: Generic Access Profile
_centralMan = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[_centralMan scanForPeripheralsWithServices:[NSArray arrayWithObject:uuid]
                                    options:nil];

我找不到我的外围设备,但是当我使用时:

I cannot find my peripheral, but when I use:

_centralMan = [[CBCentralManager alloc] initWithDelegate:self queue:nil];
[_centralMan scanForPeripheralsWithServices:nil
                                    options:nil];

…它会立即显示。

连接后,便可以发现/读取/写入我期望的所有服务。我的理解是,GAP使这成为可能。我还尝试了 CBUUID 的其他我知道正在运行的服务(特别是TX电源服务 1804),但无济于事;扫描永远不会发现任何东西。

When I connect, I am able to discover/read/write to all the services I am expecting. My understanding is that GAP makes this possible. I have also tried CBUUID's for other services that I know are running (specifically "1804", TX power service), to no avail; the scan never discovers anything.

即使服务正在运行(在连接时我也可以与它们通信),当我扫描传递服务UUID数组为<$ c时$ c> nil ,此委托方法称为...

Even though the services are running (I can communicate w/ them upon connecting), when I scan passing the service UUID array as nil and this delegate method is called...

-(void) centralManager:(CBCentralManager *)central 
 didDiscoverPeripheral:(CBPeripheral *)peripheral 
     advertisementData:(NSDictionary *)advertisementData 
                  RSSI:(NSNumber *)RSSI {
    DEBUG_LOG(@"Found peripheral w/ UUID: %@ RSSI: %@ \n AdvData: %@",peripheral.UUID,RSSI,advertisementData);
    DEBUG_LOG(@"Services found: %d",peripheral.services.count);
    for (CBService * service in peripheral.services) {
        DEBUG_LOG(@"Found service: %@ w/ UUID %@",service, service.UUID);
    }
}

…它始终报告找到的服务:0。我是否应该期望 services 数组填充有在扫描过程中找到的服务? (基于 scanForPeripheralsWithServices:[NSArray arrayWithObject:uuid]
options:nil
,我认为这至少是部分可行的。)

…it always reports "Services found: 0". Should I expect the services array to be populated w/ services found during the scan? (I assume this is at least partially possible, based on scanForPeripheralsWithServices:[NSArray arrayWithObject:uuid] options:nil.)

我的外围设备的服务广告有问题吗?我使用API​​的方式有误吗?任何指导,不胜感激! :-)

Could this be a problem w/ my peripheral's service advertisements? Am I using the API incorrectly? Any guidance is much appreciated! :-)

PS:我的蓝牙很绿色。

PS: I'm pretty green w/ Bluetooth.

PPS:我控制信号源到外围设备(这是CC2540DK)。因此,我很可能会相信问题就在这里。

PPS: I control the source to the peripheral (it's a CC2540DK). So I'd be as likely to believe the problem is there as it is here.

推荐答案

原来我们的外围代码不是在此蓝牙规范。

Turns out our peripheral code was not advertising the UUIDs a la this Bluetooth spec.

我们将它们放入广告包后,iOS便毫不费力地捡起它们。

As soon as we dropped them into the advertising packet, iOS picked them up no sweat.

这篇关于扫描特定服务CBUUID时找不到外围设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆