Fr0zt
Fr0zt

Reputation: 1255

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?

Thanks.

Upvotes: 0

Views: 274

Answers (1)

Rob
Rob

Reputation: 2660

You can use locationM.stopUpdatingLocation()

Start updating location

 override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)

    locationM.startUpdatingLocation()


}

And Stop

override func viewWillDisappear(_ animated: Bool) {
    super.viewWillDisappear(animated)
    locationM.stopUpdatingLocation()
}

Upvotes: 1

Related Questions