禁用启用了significantChange的位置

时间:2016-08-23 13:48:29

标签: ios swift

我使用significantChange监控设备位置,一切正常,每次更改我都会在我的webservice上更新位置。

如果用户关闭系统位置会发生什么?是一次再次调用significantChange,所以我可以设置用户已禁用该位置吗?

1 个答案:

答案 0 :(得分:0)

viewDidlaod()中的某些内容可以检查位置服务的状态。

override func viewDidLoad() {
  if CLLocationManager.locationServicesEnabled() {
    switch(CLLocationManager.authorizationStatus()) {
    case .NotDetermined, .Restricted, .Denied:
        print("No access")
    case .AuthorizedAlways, .AuthorizedWhenInUse:
        print("Access")
     }
  } else {
    print("Last know location: \(location)" // retrieve this from the location you saved it. 
    // You could also then set some value on your sever to show that it has been turned off. 
    print("Location services are not enabled")
    }
  }
}

然后在didUpdateLocations保存最后一个位置。

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
  let location = locations.last // save this in defaults or some way to revive at a later time.
}