2

I basically want search the nearby BLE devices from my iOS app, even when the app is in background.

iOS provides this method:

//_cbcManager is the object of CBCentralManager

[_cbcManager scanForPeripheralsWithServices:nil options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]]

This method will scan for all the services (since nil is provided in the parameter). But this won't work in background. iOS needs specific service names when the app is in background.

I basically want to scan the audio devices, reading this page: https://developer.bluetooth.org/gatt/services/Pages/ServicesHome.aspx I have provided most of the generic services that an audio device may broadcast. So now, the method looks something like this:

[_cbcManager scanForPeripheralsWithServices:@[[CBUUID UUIDWithString:@"180A"], [CBUUID UUIDWithString:@"1815"], [CBUUID UUIDWithString:@"1800"], [CBUUID UUIDWithString:@"1801"], [CBUUID UUIDWithString:@"1807"], [CBUUID UUIDWithString:@"180E"], [CBUUID UUIDWithString:@"1813"], [CBUUID UUIDWithString:@"181C"]] options:[NSDictionary dictionaryWithObject:[NSNumber numberWithBool:NO] forKey:CBCentralManagerScanOptionAllowDuplicatesKey]]

Is there a specific/generic service name which every BLE device will broadcast?

nr5
  • 4,228
  • 8
  • 42
  • 82
  • Most devices will advertise 'Device Information' 0x180A, but this could be anything from a fitness band to a iPhone. Many audio devices will use legacy Bluetooth, not BLE, so they won't show up anyway – Paulw11 Aug 10 '15 at 08:01
  • Legacy bluetooth? but there is no way to scan that from iOS ?? EA framework only allows apple certified devices. – nr5 Aug 10 '15 at 09:32
  • Did you get it working? Do let us know your accepted answer. – instaable Sep 10 '15 at 06:21
  • Its kind of a restriction. You cannot search for all of them in the background and not all of them broadcasts the UUID mentioned on the bluetooth developer page. So you have to live with it....180F will get broadcasted only if the device has battery. For instance, car audio does not have a battery, so 180F will not be detected. – nr5 Sep 10 '15 at 10:10

1 Answers1

1

You can always check for the Battery Service at UUID 0x180F.

More details at: https://developer.bluetooth.org/gatt/services/Pages/ServiceViewer.aspx?u=org.bluetooth.service.battery_service.xml

In case you missed to get the BLE connection working in the background:

A) request for background mode by adding the following key to your info.plist: Required background modes (array). Add App communicates using CoreBluetooth item to this array.

OR

B) Go to Targets Settings/Capabilities. Turn ON and expand Background Modes. Check the Uses Bluetooth LE accessories. This adds the Required background modes key to your info plist file.

instaable
  • 3,449
  • 2
  • 24
  • 31