what do you do to get a location capturer to run before an override segue?

If I understand it correctly in viewDidAppear(_:) you have one condition. If it’s true you immediately trying to perform the segue.

if  Auth.auth().currentUser != nil {
    self.performSegue(withIdentifier: "tohome", sender: nil)
}

As location is must to move into HomeScreen, why don’t you do the navigation(segue) when you receive the first location update inside CLLocationManagerDelegate?

func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation])   {
      // check for existing location if we received earlier
      guard self.latestLoc == nil else {
         // we received one location earlier, navigation to Home completed. no need to proceed 
         // If we no longer need to listen for loc updates, we can stop listening further
         manager.stopUpdatingLocation()
         return
      } 
      // ... Your exiting data base update code
     guard let latestLoc = locations.last else { return }
     self.latestLoc = latestLoc // If you want to pass this location to destination view controller in `prepare(for: UIStoryboardSegue, sender: Any?)`
     // Also it will good practice to call manager.stopUpdatingLocation() if you need location only for once 

     // Now move to HomeScreen
     self.performSegue(withIdentifier: "tohome", sender: nil)

     // If we no longer need to listen for loc updates, we can stop listening further
     manager.stopUpdatingLocation()
}

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top