H.N. H.N. - 10 months ago 53
Swift Question

Stop updating location when view (map) is not showing

I have an app with a map loaded immediately after the app starts.
Now I have some views in the app.
WHat I'd like to do is, whene I leave my mapview, into another view, I'd like the map to stop updating self location and than, only start updating again self location, when I come back to that map view.
(self location = user current location).

Anyone can tell me how to do that please?


Rob Rob
Answer Source

You can use locationM.stopUpdatingLocation()

Start updating location

 override func viewDidAppear(_ animated: Bool) {



And Stop

override func viewWillDisappear(_ animated: Bool) {