marco.bollati
marco.bollati

Reputation: 41

CoreLocation on macOS always return location services disabled

I'm stuck on using CoreLocation on macOS High Sierra.

I need to get current user location but this code:

if (CLLocationManager.locationServicesEnabled()) {
        switch CLLocationManager.authorizationStatus() {
        case .restricted:
            print("You don't have permission to use Location Services.")
        case .denied:
            print("You denied permission to use Location Services, please enable it in Preferences.")
        case .notDetermined:
            print("Non determinati")
            self.locationManager.startUpdatingLocation()
        default: ()
        }
    }
    else {
        print("Location services disabled")
    }

always print "Location services disabled".

locationManager is a class property initialized at instance creation.

Even trying to use a MapView with showUserLocation = true doesn't work. In my Mac settings I have Location Services enabled but my app doesn't show on list (maybe because it has never requested user location access).

I already setted "Privacy - Location When In Use Usage Description" on my app Info.plist file Anyone knows how to ask correctly for user location? I'm currently running my app directly from XCode.

Upvotes: 1

Views: 1292

Answers (2)

SUMIT NIHALANI
SUMIT NIHALANI

Reputation: 417

check if the you have turned on AppSandbox in capabilities. Turn it off and try again. This fixed the problem for me.

Upvotes: 1

Enea Dume
Enea Dume

Reputation: 3232

hgj

in your info.plist add this Privacy - Location When In Use Usage Description , type String and in value write why are you asking for location

Upvotes: 0

Related Questions