I created "updateheading" in settings bundle
If user leave the app, go to setting to change value, when user go back the app, locationManager should start/stop base on the updated value.
But the app does not run viewWillAppear. How to read updated value?
private let locationManager : CLLocationManager = CLLocationManager()
override func viewDidLoad() {
super.viewDidLoad()
locationManager.requestWhenInUseAuthorization()
locationManager.delegate = self
}
override func viewWillAppear(_ animated: Bool) {
let userDefault = UserDefaults.standard
let updateheading = userDefault.object(forKey: "updateheading") as! Bool
if(updateheading){
locationManager.startUpdatingHeading()
}else{
locationManager.stopUpdatingHeading()
}
}