Q:

Swift detect when returned from UIApplication.shared.open

Originally I wanted to display google map directions in my app but I don't think that is possible to do. So what I'm going to do is have my app open Google Maps app when needed.
I can open Google Maps just fine however I would like to have my app segue to another screen once they have reached their destination.
Is there any way of detecting that? If not what's the best way to segue to another view controller once the user returns to my app?
Here is my code:
  override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){
    if let cell = tableView.cellForRow(at: indexPath) as? LocationCell {
        if(indexPath.row == 0){
            cell.selectionStyle = .none
            browseVillages(cell.villageBtn)
        }

        else{
            cell.selectionStyle = .none

            let googleMaps = URL(string: "comgooglemaps-x-callback://")!
            if UIApplication.shared.canOpenURL(googleMaps) {
                let directionsRequest = "comgooglemaps-x-callback://" +
                    "?daddr=\(bars[indexPath.row]["Latitude"]!),\(bars[indexPath.row]["Longitude"]!)&saddr=\(currentLocation!.coordinate.latitude),\(currentLocation!.coordinate.longitude)" +
                "&x-success=MYAPP://?resume=true&x-source=AirApp"

                let directionsURL = URL(string: directionsRequest)!
                UIApplication.shared.open(directionsURL, options: [:], completionHandler: nil)
            }
            else {
                let alert = UIAlertController(title: "Error", message: "MYAPP uses Google Maps to display accurate directions to \(bars[indexPath.row]["Name"]).", preferredStyle: UIAlertControllerStyle.alert)
                alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil))
                self.present(alert, animated: true, completion: {  })
            }
        }
    }
}

A:

Register the "comeFromMaps" UserDefaults as false at some place like application(_:didFinishLaunchingWithOptions:), then place this just before you open the maps link:
UserDefaults.standard.set(true, forKey: "comeFromMaps")

Then place this in application​Did​Become​Active(_:​) of your AppDelegate:
let comeFromMaps = UserDefaults.standard.bool(forKey: "comeFromMaps")
if comeFromMaps {
    UserDefaults.standard.set(false, forKey: "comeFromMaps")
    // perform the segue!
}

Also, you can use MapKit to get the directions, using the MKDirections class.

