6

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?

Community
  • 1
  • 1
Smeegol
  • 1,609
  • 4
  • 26
  • 40

3 Answers3

7

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];
allprog
  • 15,913
  • 8
  • 54
  • 94
1

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.

Tommy Devoy
  • 13,279
  • 3
  • 46
  • 75
  • I have occasionally seen Bluetooth LE devices (usually ones I misconfigured and forgot to have advertise a particular service when advertising the device) be missed on a scan for a particular service. If you nil out the service and run the scan, you can look at all the devices it returns to verify the device is even being picked up as advertising at all, then to see what services it advertises. – Brad Larson Aug 19 '13 at 20:07
1

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.

Smeegol
  • 1,609
  • 4
  • 26
  • 40
  • 1
    Nice for you. Bad for us, who provided answers. I guess it would be fair from you to vote on us. Remember, it doesn't cost you anything and actually, the proposed solutions can help future visitors of this question. – allprog Aug 20 '13 at 21:36
  • @Smeegol what type of Bluetooth 4.0 LE device you used, i tried with Cirago BT8000 LE device, but it's not detecting. Please mention the bluetooth dongle name which we can use for ios. Thanks in advance! –  Apr 29 '14 at 12:20