Check if location services are enabled

前端 未结 9 1706
情话喂你
情话喂你 2020-12-02 08:34

I\'ve been doing some research about CoreLocation. Recently, I encountered a problem that has been covered elsewhere, but in Objective C, and for iOS 8.

I feel kinda

9条回答
  •  执念已碎
    2020-12-02 09:25

    It is just a 2 line function in Swift 4:

    import CoreLocation
    
    static func isLocationPermissionGranted() -> Bool
    {
        guard CLLocationManager.locationServicesEnabled() else { return false }
        return [.authorizedAlways, .authorizedWhenInUse].contains(CLLocationManager.authorizationStatus())
    }
    

提交回复
热议问题