CoreLocation在MacOS总是返回禁用位置服务

问题描述 投票:0回答:2

我卡在在MacOS海伊谢拉使用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中运行我的应用程序。

swift macos core-location macos-high-sierra location-services
2个回答
0
投票

HGJ

在您的info.plist添加此Privacy - Location When In Use Usage Description,类型String和值写入你为什么要问的位置


0
投票

检查你的能力开启AppSandbox。关闭它,然后再试一次。这解决了这个问题对我来说。

© www.soinside.com 2019 - 2024. All rights reserved.