When I use iOS bluetooth, code like this:
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?
My device is iPod touch 5 (jailbroken) with iOS 6. I have already test some bluetooth 4.0 devices. Can anyone tell me why?
Scan with nil
services to check whether the peripheral you are looking for actually advertises anything. When the centralManager:didDiscoverPeripheral:advertisementData:RSSI:
is called, check out the advertisement data. Simply NSLog()
it. If 0x1802 is not in it, then the peripheral is not advertising this service and the scanner will not find it this way. 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) ?? You can print this out inside the CBPeripheralManagerDelegate peripheralManagerDidStartAdvertising:
callback. You can also just scan for nil with both apps in the foreground and look inside the advertisement data to verify. 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.
Thank you thousand times, but I have to say sorry. Then I tested my code with another Bluetooth 4.0 LE device. It works! It means my former Bluetooth 4.0 devices are not LE version. They told me wrong thing! Thank you and say sorry for wasting your time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With