Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/96.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 禁用启用了重大更改的位置_Ios_Swift - Fatal编程技术网

Ios 禁用启用了重大更改的位置

Ios 禁用启用了重大更改的位置,ios,swift,Ios,Swift,我监视设备的位置有重大变化,一切正常,每次变化我都会在我的Web服务上更新位置 override func viewDidLoad() { if CLLocationManager.locationServicesEnabled() { switch(CLLocationManager.authorizationStatus()) { case .NotDetermined, .Restricted, .Denied: print("No access")

我监视设备的位置有重大变化,一切正常,每次变化我都会在我的Web服务上更新位置

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

如果用户关闭系统位置,会发生什么情况?是否再次调用重大更改,以便我可以设置用户已禁用位置?

在您的
viewdilaod()
中执行类似操作,以检查位置服务的状态

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.
}

在您的
viewdilaod()
中执行类似的操作,以检查位置服务的状态

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.
}

:但是AuthorizationChanges事件能否重新启动我的应用程序?如果你的应用程序被强制终止,那么你将无法获得位置更新。如果你的应用程序由于内存压力而被暂停或终止,那么你仍然应该得到对此委托方法的调用。这很容易尝试。我可以说,一旦位置被禁用,您将不会获得任何位置更新:但AuthorizationChanges事件是否可以重新启动我的应用程序?如果您的应用程序被强制终止,那么您无论如何也不会获得位置更新。如果你的应用程序由于内存压力而被暂停或终止,那么你仍然应该得到对此委托方法的调用。这很容易尝试。我可以说,一旦位置被禁用,您将不会得到任何位置更新