如何在iOS中以编程方式禁用位置服务?

时间:2016-10-19 10:31:48

标签: ios swift cllocationmanager

我有以下内容:

class AppDelegate: UIResponder, UIApplicationDelegate, CLLocationManagerDelegate {
    ...
    let locationManager = CLLocationManager()

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        if CLLocationManager.locationServicesEnabled() {
            locationManager.delegate = self
            locationManager.allowsBackgroundLocationUpdates = true
            locationManager.distanceFilter = 3000.0
            locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers
            locationManager.requestAlwaysAuthorization()
            locationManager.startUpdatingLocation()
        }
    }

    func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
        print("my location: \(locations.first?.coordinate)")
        locationManager.stopUpdatingLocation()
        locationManager.delegate = nil
    }
}

但即使关闭应用程序,我也会在状态栏中看到位置服务图标:

enter image description here

我想知道是否有办法以编程方式禁用它。提前谢谢!

1 个答案:

答案 0 :(得分:0)

在plist文件中,您必须确保位置行为Privacy - LocationAlwaysUsageDescription而不是var myApp = angular.module('myAppUpdate',[]) //this is called twice in your code, with the brackets you are //instanciating the module.