Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS bluetooth scanForPeripheralsWithServices no results

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?

like image 764
Smeegol Avatar asked Aug 19 '13 11:08

Smeegol


3 Answers

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];
like image 69
allprog Avatar answered Nov 17 '22 05:11

allprog


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.

like image 42
Tommy Devoy Avatar answered Nov 17 '22 03:11

Tommy Devoy


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.

like image 1
Smeegol Avatar answered Nov 17 '22 03:11

Smeegol