See Also: CLBeacon Members
Beacons are Bluetooth (often Bluetooth LE) devices that can be detected by apps. Currently, beacons are iOS devices, but Apple has stated that they intend to release a Bluetooth profile for beacons. (Current non-Apple iBeacon devices use formats apparently based on reverse-engineered signals.)
Beacons can be used to created CoreLocation.CLRegions that can be monitored for entry and exit, as shown in the following code:
C# Example
locationManager = new CLLocationManager();
NSUuid beaconId = new NSUuid("E437C1AF-36CE-4BBC-BBE2-6CE802977C46");
var beaconRegion = new CLBeaconRegion(beaconId, "My Beacon");
locationManager.RegionEntered += (s,e) => {
if(e.Region.Identifier == "My Beacon")
{
Console.WriteLine("Found My Beacon");
}
};
locationManager.StartMonitoring(beaconRegion);
iBeacons also support "ranging" for determining physical proximity with a higher precision with the Foundation.CLBeacon.Proximity property. The following example shows the basic use of ranging:
C# Example
locationManager.StartRangingBeacons(beaconRegion);
locationManager.DidRangeBeacons += (lm, rangeEvents) => {
switch(rangeEvents.Beacons[0].Proximity)
{
case CLProximity.Far :
Console.WriteLine("You're getting colder!");
break;
case CLProximity.Near :
Console.WriteLine("You're getting warmer!");
break;
case CLProximity.Immediate :
Console.WriteLine("You're red hot!");
break;
case CLProximity.Unknown :
Console.WriteLine("I can't tell");
break;
default:
throw new ArgumentOutOfRangeException();
}
};
F# Example
locationManager.DidRangeBeacons.Add(fun rangeEvents ->
let s = match rangeEvents.Beacons.[0].Proximity with
| CLProximity.Far -> "You're getting colder!"
| CLProximity.Near -> "You're getting warmer!"
| CLProximity.Immediate -> "You're red hot!"
| CLProximity.Unknown -> "I can't tell"
| _ -> raise(ArgumentOutOfRangeException("Unknown argument"))
Console.WriteLine(s)
)
locationManager.StartRangingBeacons(beaconRegion)
Applications can broadcast themselves as beacons by passing the CLBeaconRegion.PeripheralData property of a CoreLocation.CLBeaconRegion to CoreBluetooth.CBPeripheralManager.StartAdvertising.