Reputation: 11
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.
Please help me, I am new to iOS programming. Any ideas?
Upvotes: 1
Views: 2120
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:
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