CBBeaconManager Class Reference

Inherits from NSObject
Declared in CBBeaconManager.h
CBBeaconManager.m

Overview

The CBBeaconManager object is your entry point to the beacon scanning service.

  delegate

The delegate of CBBeaconManager.

@property (assign, nonatomic, nullable) id<CBBeaconManagerDelegate> delegate

Declared In

CBBeaconManager.h

– requestWhenInUseAuthorization

Requests permission to use location services while the app is in the foreground.

- (void)requestWhenInUseAuthorization

Discussion

When +authorizationStatus == CBAuthorizationStatusNotDetermined, calling this method will trigger a prompt to request “when-in-use” authorization from the user. If possible, perform this call in response to direct user request for a location-based service so that the reason for the prompt will be clear. Any authorization change as a result of the prompt will be reflected via the usual delegate callback: -didChangeAuthorizationStatus:.

If received, “when-in-use” authorization grants access to the user’s location via -startRangingBeaconsInRegion while in the foreground.

If updates have been started when going to the background, then a status bar banner will be displayed to maintain visibility to the user, and updates will continue until stopped normally, or the app is killed by the user.

“When-in-use” authorization does NOT enable monitoring API on regions, significant location changes, or visits, and -startRangingBeaconsInRegion will not succeed if invoked from the background.

When +authorizationStatus != CBAuthorizationStatusNotDetermined, (ie generally after the first call) this method will do nothing.

If the NSLocationWhenInUseUsageDescription key is not specified in your Info.plist, this method will do nothing, as your app will be assumed not to support WhenInUse authorization.

Declared In

CBBeaconManager.h

– requestAlwaysAuthorization

Requests permission to use location services whenever the app is running.

- (void)requestAlwaysAuthorization

Discussion

When +authorizationStatus == CBAuthorizationStatusNotDetermined, calling this method will trigger a prompt to request “always” authorization from the user. If possible, perform this call in response to direct user request for a location-based service so that the reason for the prompt will be clear. Any authorization change as a result of the prompt will be reflected via the usual delegate callback: -didChangeAuthorizationStatus:.

If received, “always” authorization grants access to the user’s location via any CBBeaconManager API, and grants access to launch-capable monitoring API such as region monitoring, significante location visits, etc. Even if killed by the user, launch events triggered by monitored regions or visit patterns will cause a relaunch.

“Always” authorization presents a significant risk to user privacy, and as such requesting it is discouraged unless background launch behavior is genuinely required. Do not call -requestAlwaysAuthorization unless you think users will thank you for doing so.

When +authorizationStatus != CBAuthorizationStatusNotDetermined, (ie generally after the first call) this method will do nothing.

If the NSLocationAlwaysUsageDescription key is not specified in your Info.plist, this method will do nothing, as your app will be assumed not to support Always authorization.

Declared In

CBBeaconManager.h

– requestStateForRegion:

Asynchronously retrieve the cached state of the specified region. The state is returned to the delegate via didDetermineState:forRegion:.

- (void)requestStateForRegion:(CBRegion *_Nonnull)region

Parameters

region

The region whose state you want to know. This object must be an instance of one of the standard region subclasses provided by Map Kit. You cannot use this method to determine the state of custom regions you define yourself.

Discussion

Retrieves the state of a region asynchronously.

This method performs the request asynchronously and delivers the results to the beacon manager’s delegate. You must implement the didDetermineState:forRegion: method in the delegate to receive the results.

If the region parameter contains an unknown type of region object, this method does nothing.

Declared In

CBBeaconManager.h

– startRangingBeaconsInRegion:

Start calculating ranges for beacons in the specified region.

- (void)startRangingBeaconsInRegion:(CBRegion *_Nonnull)region

Parameters

region

The region object that defines the identifying information for the targeted beacons. The number of beacons represented by this region object depends on which identifier values you use to initialize it. Beacons must match all of the identifiers you specify. This method copies the region information it needs from the object you provide.

Discussion

Starts the delivery of notifications for beacons in the specified region.

Once registered, the beacon manager reports any encountered beacons to its delegate by calling the didRangeBeacons:inRegion: method. If there is an error registering the specified beacon region, the beacon manager calls its delegate’s rangingBeaconsDidFailForRegion:withError: method and provides the appropriate error information.

Declared In

CBBeaconManager.h

– startRangingBeaconsInRegions:

Start calculating ranges for beacons in the specified regions.

- (void)startRangingBeaconsInRegions:(NSArray<CBRegion*> *_Nonnull)regions

Parameters

regions

The array region object that defines the identifying information for the targeted beacons. The number of beacons represented by this region object depends on which identifier values you use to initialize it. Beacons must match all of the identifiers you specify. This method copies the region information it needs from the object you provide.

Discussion

Starts the delivery of notifications for beacons in the specified regions.

Once registered, the beacon manager reports any encountered beacons to its delegate by calling the didRangeBeacons:inRegion: method. If there is an error registering the specified beacon region, the beacon manager calls its delegate’s rangingBeaconsDidFailForRegion:withError: method and provides the appropriate error information.

Declared In

CBBeaconManager.h

– stopRangingBeaconsInRegion:

Stop calculating ranges for the specified region.

- (void)stopRangingBeaconsInRegion:(CBRegion *_Nonnull)region

Parameters

region

The region that identifies the beacons. The object you specify need not be the exact same object that you registered but the beacon attributes should be the same.

Discussion

Stops the delivery of notifications for the specified beacon region.

Declared In

CBBeaconManager.h

– startMonitoringForRegion:

Start monitoring the specified region.

- (void)startMonitoringForRegion:(CBRegion *_Nonnull)region

Parameters

region

The region object that defines the boundary to monitor. This parameter must not be nil.

Discussion

You must call this method once for each region you want to monitor. If an existing region with the same identifier is already being monitored by the app, the old region is replaced by the new one. The regions you add using this method are shared by all beacon manager objects in your app and stored in the monitoredRegions property.

Region events are delivered to the didEnterRegion: and didExitRegion: methods of your delegate. If there is an error, the beacon manager calls the monitoringDidFailForRegion:withError: method of your delegate instead.

An app can register up to 20 regions at a time. In order to report region changes in a timely manner, the region monitoring service requires network connectivity.

Declared In

CBBeaconManager.h

– startMonitoringForRegions:

Start monitoring for the scpeciefied regions.

- (void)startMonitoringForRegions:(NSArray<CBRegion*> *_Nonnull)regions

Parameters

regions

The array of region object that defines the boundary to monitor. This parameter must not be nil.

Discussion

You must call this method once for each region you want to monitor. If an existing region with the same identifier is already being monitored by the app, the old region is replaced by the new one. The regions you add using this method are shared by all beacon manager objects in your app and stored in the monitoredRegions property.

Region events are delivered to the didEnterRegion: and didExitRegion: methods of your delegate. If there is an error, the beacon manager calls the monitoringDidFailForRegion:withError: method of your delegate instead.

An app can register up to 20 regions at a time. In order to report region changes in a timely manner, the region monitoring service requires network connectivity.

Declared In

CBBeaconManager.h

– stopMonitoringForRegion:

Stop monitoring the specified region.

- (void)stopMonitoringForRegion:(CBRegion *_Nonnull)region

Parameters

region

The region object currently being monitored. This parameter must not be nil.

Discussion

If the specified region object is not currently being monitored, this method has no effect. It is valid to call stopMonitoringForRegion: for a region that was registered for monitoring with a different beacon manager object, during this or previous launches of your application.

This is done asynchronously and may not be immediately reflected in monitoredRegions.

Declared In

CBBeaconManager.h