iOS Tutorial iBeacons

iBeacons are small, low powered peripherals, that use BLE (Bluetooth Low Energy) to advertise their information.

The BeaconParser class can be used together with the BLE library to search for beacons. On Android, BeaconParser will find iBeacons, however not on iOS. iOS treats iBeacons in a different way.

The attached example extends the Location library with inline Objective C code to search for iBeacons.

You need to know the iBeacon UDID of the beacon you are searching for.
The user will need to first allow the app to access the location services (don't miss the two #PlistExtra lines).


The DidRangeBeacons event will be raised when a beacon is discovered:
B4X:
Sub LocManager_DidRangeBeacons (Beacons As List)
   For Each Beacon As NativeObject In Beacons
     Dim UUID As String = Beacon.GetField("proximityUUID").AsString
     Dim Major As Int = Beacon.GetField("major").AsNumber
     Dim Minor As Int = Beacon.GetField("minor").AsNumber
     Dim proximity As Int = Beacon.GetField("proximity").AsNumber '0 = unknown, 1 = immediate, 2 = near, 3 = far
     Dim rssi As Int = Beacon.GetField("rssi").AsNumber
     TextView1.Text = $"Beacon found: ${UUID}
Major: ${Major}
Minor: ${Minor}
Proximity: ${proximity}
RSSI: ${rssi}
Time: $Time{DateTime.Now}
"$
   Next
End Sub


upload_2017-5-7_15-10-33.png



Note that you can use another iOS device to emulate an iBeacon. For example: https://itunes.apple.com/de/app/beacon-tx/id1036165476?l=en&mt=8
 

Attachments

  • iBeacon.zip
    3.1 KB · Views: 583
Top