문제 설명
MKMapView에 주석을 추가할 때 백그라운드에서 앱 충돌 (Crashes app in background when adding annotation on MKMapView)
주석을 추가한 후 사용자가 앱을 백그라운드에 넣으면 1초 후에 충돌합니다. 전경에서는 충돌하지 않습니다. 충돌에 대한 로그에는 표시되지 않습니다.
viewDidLoad() 메서드에서 주석 추가
let annotation = MKPointAnnotation()
annotation.coordinate = CLLocationCoordinate2D(latitude: lat as! Double, longitude: long as! Double)
mapView.addAnnotation(annotation)
위임 메서드 코드:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) ‑> MKAnnotationView? {
let pin = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: nil)
pin.canShowCallout = true
let button = UIButton(type: .detailDisclosure)
pin.rightCalloutAccessoryView = button
return pin
}
충돌 로그:
제가 뭘 잘못하고 있는지 알려주세요.
업데이트
MKMapView에서 단순히 주석을 추가하여 새 프로젝트를 만든 후에도. 그것은 내 것과 동일하게 행동합니다. 글로벌 프레임워크 문제입니까? 마주한/대면한 다른 남자가 있습니까?<
참조 솔루션
방법 1:
Using expressions like lat as! Double
is almost always a bad idea.
Try something like if let lat = lat as? Double
and make a nice error handling if that fails.
(by Manish、Gerd Castan)