macOS上的CoreLocation始终返回禁用的位置服务

时间:2018-02-21 09:24:10

标签: swift macos core-location macos-high-sierra location-services

我坚持在macOS High Sierra上使用CoreLocation。

我需要获取当前用户位置,但是这段代码:

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")
    }

始终打印“禁用位置服务”。

locationManager是在创建实例时初始化的类属性。

即使尝试将MapView与showUserLocation = true一起使用也无效。 在我的Mac设置中,我启用了位置服务,但我的应用程序未显示在列表中(可能是因为它从未请求用户位置访问)。

我已经在我的应用Info.plist文件中设置了“隐私 - 使用时的位置使用说明” 任何人都知道如何正确地询问用户位置?我目前正在直接从XCode运行我的应用程序。

2 个答案:

答案 0 :(得分:0)

HGJ

在您的info.plist中添加此Privacy - Location When In Use Usage Description,输入String,并在值写中为什么要求提供位置

答案 1 :(得分:0)

检查您是否已打开功能中的AppSandbox。 将其关闭,然后重试。 这为我解决了这个问题。