iOS蓝牙scanForPeripheralsWithServices没有结果

谢小进*_*谢小进 5 bluetooth ios core-bluetooth bluetooth-lowenergy

当我使用iOS蓝牙时,代码如下:

static NSString * const kServiceUUID = @"1802";
[self.manager scanForPeripheralsWithServices:@[ [CBUUID UUIDWithString:kServiceUUID] ] options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @NO }];
Run Code Online (Sandbox Code Playgroud)

为什么没有回应?我在方法scanForPeripheralsWithServices中尝试了各种参数对我已经检查了这个问题: 如何获取可用蓝牙设备的列表?

我的设备是iOS 6的iPod touch 5(越狱).我已经测试了一些蓝牙4.0设备.谁能告诉我为什么?

all*_*rog 7

扫描nil服务以检查您要查找的外围设备是否实际发布了任何内容.当centralManager:didDiscoverPeripheral:advertisementData:RSSI:被调用时,检查出的广告数据.简单NSLog()来说 如果不包含0x1802,则外围设备不会宣传此服务,扫描仪也不会以这种方式找到它.要更正此问题,请在广告设置中包含该服务:

NSDictionary *advData = 
 @{CBAdvertisementDataServiceUUIDsKey:@[[CBUUID UUIDWithString:@"1802"]]};
[peripheralManager startAdvertising:advData];
Run Code Online (Sandbox Code Playgroud)

  • 仍然没有为我工作.但我明白了.我在状态更改为CBCentralManagerStatePoweredOn之前开始扫描. (3认同)