I found that running some code to display the location in the form of maps MKMapItem.openInMaps()
works exactly 50% of the time.
In fact, it exactly alternates with the displayed MKPlacemark
and is not displayed.
For example, every 1st, 3rd, 5th, 7th ... nth time the code is run, it displays a placemark, but every 2nd, 4th, 6th, 8 th ... at the time of its launch, the place mark is not displayed.
This is a 100% reproducible code posted below.
This is similar to his mistake, but if so, I am surprised that he was not reported and not fixed earlier. But given the fact that failures exactly alternate between success and failure, I make you think that something else is happening, so I am posting here to find out if anyone is familiar with this problem, or is there something that you need to do what is missing from the code, or there is a workaround:
override func viewDidAppear(_ animated: Bool) { displayMap() } func displayMap() { let geoCoder = CLGeocoder() geoCoder.geocodeAddressString("1 Infinite Loop, Cupertino,California") { (placemark: [CLPlacemark]?, error: Error?) -> Void in if error == nil { if let placemark = placemark, placemark.count > 0 { let location = placemark.first let latitude = (location?.location?.coordinate.latitude)! let longitude = (location?.location?.coordinate.longitude)! let coordinates = CLLocationCoordinate2DMake(latitude, longitude) let regionDistance:CLLocationDistance = 100000 let regionSpan = MKCoordinateRegionMakeWithDistance(coordinates, regionDistance, regionDistance) let options = [ MKLaunchOptionsMapCenterKey: NSValue(mkCoordinate: regionSpan.center), MKLaunchOptionsMapSpanKey: NSValue(mkCoordinateSpan: regionSpan.span) ] let placemark = MKPlacemark(coordinate: coordinates, addressDictionary: nil) let mapItem = MKMapItem(placemark: placemark) mapItem.name = "Apple" mapItem.phoneNumber = "(405) 123-4567" mapItem.openInMaps(launchOptions: options) } } else { assert(false, "Unable to geocode") } } }
Here's what the result looks like when the code runs for the first, third, fifth, seventh ... time

And this is the result when the code is run for the second, fourth, sixth, eighth ... time

Pay attention to the screenshot of the failure, which is not only not marked on the place map, but the slide up is also empty.
(Currently it is observed on 10.2, but saw other versions)