Janaki
Janaki

Reputation: 11

How to scan and connect to iBeacon using BLE services in the background

I have a iBeacon device with services advertising. I need to know to how to connect to the iBeacon from the iOS app in the background mode.

  1. I know the service UUID of the iBeacon but I am not able to scan using serviceUUID in foreground and background mode.
  2. If I scan for nil and filter using the name, working in the foreground but not in the background.

Please help me, I am new to iOS programming. Any ideas?

Upvotes: 1

Views: 2120

Answers (1)

davidgyoung
davidgyoung

Reputation: 64916

Don't confuse the ProximityUUID of the iBeacon transmission with a GATT Service UUID. While both are 16 byte identifiers typically represented in the same hex format, the two have entirely different meanings. An iBeacon ProximityUUID cannot be used as a GATT Service UUID.

There is no requirement at all that a bluetooth beacon transmitting an iBeacon frame hosts any connectable GATT services. While some manufacturers do offer a GATT service in their hardware beacons for configuring its identifiers as well as other purposes, the GATT Service UUID is typically not the same as the ProximityUUID.

If you want to do what you describe you need to:

  1. Find out of your beacon manufacturer even hosts a GATT service at all.
  2. It yes, find out what the GATT Service UUID is. Again, it will typically not be the same as the iBeacon ProximityUUID.

If you cannot get the info from the manufacturer, you might be able to find it out by scanning in the foreground (without specifying the GATT Service UUID), then printing out the discovered GATT Service UUIDs for the device that you get by calling discoverServices on the CBPeripheral from the scan results. You may find there are no services, which would give you a no answer to the first question above.

Once you have the above info, you can scan for the beacon in the background by specifying the GATT Service UUID when starting the scan. In the background, you will not get results if you do not specify a GATT Service UUID, and even if you do results will come much more slowly.

Upvotes: 3

Related Questions