简体   繁体   English

iOS蓝牙scanForPeripheralsWithServices没有结果

[英]iOS bluetooth scanForPeripheralsWithServices no results

When I use iOS bluetooth, code like this: 当我使用iOS蓝牙时,代码如下:

static NSString * const kServiceUUID = @"1802";
[self.manager scanForPeripheralsWithServices:@[ [CBUUID UUIDWithString:kServiceUUID] ] options:@{CBCentralManagerScanOptionAllowDuplicatesKey : @NO }];

why no response? 为什么没有回应? I have tried kinds of parameter pairs in method scanForPeripheralsWithServices I have checked this question: How to get list of available Bluetooth devices? 我在方法scanForPeripheralsWithServices中尝试了各种参数对我已经检查了这个问题: 如何获取可用蓝牙设备的列表?

My device is iPod touch 5 (jailbroken) with iOS 6. I have already test some bluetooth 4.0 devices. 我的设备是iOS 6的iPod touch 5(越狱)。我已经测试了一些蓝牙4.0设备。 Can anyone tell me why? 谁能告诉我为什么?

Scan with nil services to check whether the peripheral you are looking for actually advertises anything. 使用nil服务扫描以检查您正在寻找的外围设备是否实际上做广告。 When the centralManager:didDiscoverPeripheral:advertisementData:RSSI: is called, check out the advertisement data. centralManager:didDiscoverPeripheral:advertisementData:RSSI:被调用时,检查广告数据。 Simply NSLog() it. 只需NSLog()吧。 If 0x1802 is not in it, then the peripheral is not advertising this service and the scanner will not find it this way. 如果不包含0x1802,则外围设备不会宣传此服务,扫描仪也不会以这种方式找到它。 To correct this, include the service in the advertisement setup: 要更正此问题,请在广告设置中包含该服务:

NSDictionary *advData = 
 @{CBAdvertisementDataServiceUUIDsKey:@[[CBUUID UUIDWithString:@"1802"]]};
[peripheralManager startAdvertising:advData];

Have you logged on the advertising iOS device that it is IS actually advertising the immediate alert service(1802) ?? 您是否已登录广告iOS设备,它实际上正在宣传即时警报服务(1802)? You can print this out inside the CBPeripheralManagerDelegate peripheralManagerDidStartAdvertising: callback. 您可以在CBPeripheralManagerDelegate peripheralManagerDidStartAdvertising:回调中打印出来。 You can also just scan for nil with both apps in the foreground and look inside the advertisement data to verify. 您也可以使用前景中的两个应用程序扫描nil并查看广告数据以进行验证。 Likewise, if it's a dedicated ble peripheral do the same with the device running your central manager in the foreground. 同样,如果它是专用的外围设备,则在前台运行中央管理器的设备也是如此。 If you still cannot see the peripheral (and you do not have access to the firmware for this peripheral), perhaps buy the TI Packet Sniffer to see all data packets being passed around. 如果您仍然看不到外围设备(并且您无法访问此外围设备的固件),可能需要购买TI数据包嗅探器以查看所有传输的数据包。

Thank you thousand times, but I have to say sorry. 谢谢千万次,但我不得不说对不起。 Then I tested my code with another Bluetooth 4.0 LE device. 然后我用另一台蓝牙4.0 LE设备测试了我的代码。 It works! 有用! It means my former Bluetooth 4.0 devices are not LE version. 这意味着我以前的蓝牙4.0设备不是LE版本。 They told me wrong thing! 他们告诉我错误的事! Thank you and say sorry for wasting your time. 谢谢你,并为浪费你的时间而感到抱歉。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM