Class

CLLocationManager

The object that you use to start and stop the delivery of location-related events to your app.

Declaration

class CLLocationManager : NSObject

Overview

You use instances of this class to configure, start, and stop the Core Location services. A location manager object supports the following location-related activities:

  • Tracking large or small changes in the user’s current location with a configurable degree of accuracy.

  • Reporting heading changes from the onboard compass.

  • Monitoring distinct regions of interest and generating location events when the user enters or leaves those regions.

  • Reporting the range to nearby beacons.

Assign a custom object to the delegate property, conforming to the CLLocationManagerDelegate protocol. Assign the delegate before starting any location services. The system calls the delegate's locationManager(_:didChangeAuthorization:) method immediately when the location manager is created. All location and heading-related updates and events are delivered to that delegate.

See Adding Location Services to Your App for more information.

Topics

Determining the Availability of Services

class func significantLocationChangeMonitoringAvailable() -> Bool

Returns a Boolean value indicating whether the significant-change location service is available on the device.

class func headingAvailable() -> Bool

Returns a Boolean value indicating whether the location manager is able to generate heading-related events.

class func isMonitoringAvailable(for: AnyClass) -> Bool

Returns a Boolean value indicating whether the device supports region monitoring using the specified class.

class func isRangingAvailable() -> Bool

Returns a Boolean value indicating whether the device supports ranging of beacons that use the iBeacon protocol.

class func locationServicesEnabled() -> Bool

Returns a Boolean value indicating whether location services are enabled on the device.

Receiving Data from Location Services

var delegate: CLLocationManagerDelegate?

The delegate object to receive update events.

protocol CLLocationManagerDelegate

The methods that you use to receive events from an associated location manager object.

Requesting Authorization for Location Services

func requestWhenInUseAuthorization()

Requests the user’s permission to use location services while the app is in use.

func requestAlwaysAuthorization()

Requests the user’s permission for location services whether or not the app is in use.

enum CLAuthorizationStatus

Constants indicating the app's authorization to use location services.

class func authorizationStatus() -> CLAuthorizationStatus

Returns the app’s authorization status for using location services.

Initiating Standard Location Updates

func startUpdatingLocation()

Starts the generation of updates that report the user’s current location.

func stopUpdatingLocation()

Stops the generation of location updates.

func requestLocation()

Requests the one-time delivery of the user’s current location.

var pausesLocationUpdatesAutomatically: Bool

A Boolean value indicating whether the location manager object may pause location updates.

var allowsBackgroundLocationUpdates: Bool

A Boolean value indicating whether the app should receive location updates when suspended.

var showsBackgroundLocationIndicator: Bool

A Boolean indicating whether the status bar changes its appearance when an app uses location services in the background.

var distanceFilter: CLLocationDistance

The minimum distance (measured in meters) a device must move horizontally before an update event is generated.

let CLLocationDistanceMax: CLLocationDistance

A constant indicating the maximum distance.

let kCLDistanceFilterNone: CLLocationDistance

A constant indicating that all movement should be reported.

var desiredAccuracy: CLLocationAccuracy

The accuracy of the location data.

var activityType: CLActivityType

The type of user activity associated with the location updates.

enum CLActivityType

Constants indicating the type of activity associated with location updates.

Initiating Significant Location Updates

func startMonitoringSignificantLocationChanges()

Starts the generation of updates based on significant location changes.

func stopMonitoringSignificantLocationChanges()

Stops the delivery of location events based on significant location changes.

Initiating Heading Updates

func startUpdatingHeading()

Starts the generation of updates that report the user’s current heading.

func stopUpdatingHeading()

Stops the generation of heading updates.

func dismissHeadingCalibrationDisplay()

Dismisses the heading calibration view from the screen immediately.

var headingFilter: CLLocationDegrees

The minimum angular change (measured in degrees) required to generate new heading events.

let kCLHeadingFilterNone: CLLocationDegrees

A constant indicating that all header values should be reported.

var headingOrientation: CLDeviceOrientation

The device orientation to use when computing heading values.

enum CLDeviceOrientation

Constants indicating the physical orientation of the device.

Initiating Region Monitoring

func startMonitoring(for: CLRegion)

Starts monitoring the specified region.

func stopMonitoring(for: CLRegion)

Stops monitoring the specified region.

var monitoredRegions: Set<CLRegion>

The set of shared regions monitored by all location manager objects.

var maximumRegionMonitoringDistance: CLLocationDistance

The largest boundary distance that can be assigned to a region.

Initiating Beacon Ranging Requests

func requestState(for: CLRegion)

Retrieves the state of a region asynchronously.

func startRangingBeacons(satisfying: CLBeaconIdentityConstraint)

Starts the delivery of notifications for the specified beacon constraints.

func stopRangingBeacons(satisfying: CLBeaconIdentityConstraint)

Stops the delivery of notifications for the specified beacon constraints.

var rangedBeaconConstraints: Set<CLBeaconIdentityConstraint>

The set of beacon constraints currently being tracked using ranging.

func startRangingBeacons(in: CLBeaconRegion)

Starts the delivery of notifications for the specified beacon region.

Deprecated
func stopRangingBeacons(in: CLBeaconRegion)

Stops the delivery of notifications for the specified beacon region.

Deprecated
var rangedRegions: Set<CLRegion>

The set of regions currently being tracked using ranging.

Deprecated

Initiating Visit Event Updates

func startMonitoringVisits()

Starts the delivery of visit-related events.

func stopMonitoringVisits()

Stops the delivery of visit-related events.

Getting Recently Retrieved Data

var location: CLLocation?

The most recently retrieved user location.

var heading: CLHeading?

The most recently reported heading.

Deferring Location Updates

class func deferredLocationUpdatesAvailable() -> Bool

Returns a Boolean value indicating whether the device supports deferred location updates.

Deprecated
func allowDeferredLocationUpdates(untilTraveled: CLLocationDistance, timeout: TimeInterval)

Asks the location manager to defer the delivery of location updates until the specified criteria are met.

Deprecated
func disallowDeferredLocationUpdates()

Cancels the deferral of location updates for this app.

Deprecated
let CLTimeIntervalMax: TimeInterval

A value representing an unlimited amount of time.

Related Types

typealias CLLocationDegrees

A latitude or longitude value specified in degrees.

typealias CLLocationDistance

A distance measurement (measured in meters) from an existing location.

typealias CLLocationAccuracy

The accuracy of a geographical coordinate.

Deprecated

var purpose: String?

An app-provided string that describes the reason for using location services.

class func regionMonitoringAvailable() -> Bool

Returns a Boolean value indicating whether region monitoring is supported on the current device.

Deprecated
class func regionMonitoringEnabled() -> Bool

Returns a Boolean value indicating whether region monitoring is currently enabled.

Deprecated

Relationships

Inherits From

Conforms To

See Also

Essentials

Adding Location Services to Your App

Implement features that can access information about a user’s location.

protocol CLLocationManagerDelegate

The methods that you use to receive events from an associated location manager object.