Sample Code

Ranging for Beacons

Detect that the device is in a beacon region, then use ranging to find the beacons within the region.

Download

Overview

Running this Sample App

This sample project has two features:

  • Configure your device to be a beacon. If you don’t have an iBeacon device, you can turn an iOS device into a beacon by tapping Configure a Beacon in the sample app. The UUID is hardcoded; you can optionally add a major and minor value for your beacon. Select the Enabled switch on the configuration screen to start transmitting.

  • Use ranging to find beacons around you. Using a different iOS device, run the sample app and tap Range for Beacons to scan for beacons near you. Add a UUID to range for by tapping the Add button in the upper corner of the screen. The hardcoded UUID appears by default, and you can overwrite it with other UUID values.

The sample code contains the following files:

  • ‘RangeBeaconViewController.swift’ contains a view controller that ranges a set of beacon regions that the user adds.

  • ‘ConfigureBeaconViewController.swift’ contains a view controller that configures the iOS device running this app as a beacon.

See Also

iBeacon

Determining the Proximity to an iBeacon Device

Detect beacons and determine the relative distance to them.

Turning an iOS Device into an iBeacon Device

Broadcast iBeacon signals from an iOS device.

class CLBeacon

Information about an observed iBeacon device and its relative distance to the user’s device.

class CLBeaconRegion

A region used to detect the presence of iBeacon devices.

class CLBeaconIdentityConstraint

Identity characteristics that can match one or more beacons.

Beta

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software