CreationKit Documentation

Class Location​Manager

public final class LocationManager: NSObject, CLLocationManagerDelegate  

A general LocationManger

LocationManager LocationManager CLLocationManagerDelegate CLLocationManagerDelegate LocationManager->CLLocationManagerDelegate NSObject NSObject LocationManager->NSObject

Nested Types

LocationManager.Errors

Errors that can occur in the LocationManager.

Conforms To

CLLocationManagerDelegate
NSObject

Properties

current​Location

public var currentLocation: CLLocation?  

The most recently retrieved user location.

The value of this property is nil if no location data has ever been retrieved. In iOS 4.0 and later, this property may contain a more recent location object at launch time. Specifically, if significant location updates are running and your app is terminated, this property is updated with the most recent location data when your app is relaunched (and you create a new location manager object). This location data may be more recent than the last location event processed by your app. It is always a good idea to check the timestamp of the location stored in this property. If the receiver is currently gathering location data, but the minimum distance filter is large, the returned location might be relatively old. If it is, you can stop the receiver and start it again to force an update.

Methods

request​When​InUse​Authorization()

public func requestWhenInUseAuthorization()  

Ask the manager to request whenInUse authorization from the user.

request​Always​Authorization()

public func requestAlwaysAuthorization()  

Ask the manager to request always authorization from the user.

request​When​InUse​Authorization​IfNeeded()

public func requestWhenInUseAuthorizationIfNeeded()  

Ask the manager to request whenInUse authorization from the user if needed.

fetch​Current​Location(desired​Accuracy:​completion:​)

public func fetchCurrentLocation(
    desiredAccuracy: CLLocationAccuracy = kCLLocationAccuracyBest,
    completion: @escaping (_ result: Result<CLLocation, Errors>) -> Void
  )  

Askes the manager to fetch the users current location.

Parameters

desired​Accuracy CLLocation​Accuracy

The desired accuracy of the location. Defaults to kCLLocationAccuracyBest.

completion @escaping (_ result:​ Result<CLLocation, Errors>) -> Void

The closure that will be called with the Result of the request.

result

The Result of the request.

location​Manager(_:​did​Change​Authorization:​)

func locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)  

location​Manager(_:​did​Update​Locations:​)

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])  

location​Manager(_:​did​Fail​With​Error:​)

func locationManager(_ manager: CLLocationManager, didFailWithError error: Error)