MKMapView에 주석을 추가할 때 백그라운드에서 앱 충돌 (Crashes app in background when adding annotation on MKMapView)


문제 설명

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
}

충돌 로그:

crash logs

제가 뭘 잘못하고 있는지 알려주세요.

업데이트

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 ManishGerd Castan)

참조 문서

  1. Crashes app in background when adding annotation on MKMapView (CC BY‑SA 2.5/3.0/4.0)

#mkmapview #iOS #mapkit






관련 질문

지도 보기에서 현재 위치 확대 (Zoom on Current Location in Map View)

Is there a way to restrict MKMapView Zoomlevel in iOS6 (Is there a way to restrict MKMapView Zoomlevel in iOS6)

MKMapView가 약 180도 스크롤되지 않습니다. (MKMapView does not scroll around 180 degrees)

mapView에서 길찾기 버튼을 만드는 방법은 무엇입니까? (How to create get direction button in mapView?)

MKMapview를 사용하는 동안 MB의 메모리 사용량이 발생하고 ARC를 사용하는 동안 View가 사라질 때 메모리가 해제되지 않습니다. (While using MKMapview causing MBs of memory usage and using ARC it not releasing memory when View Disappears)

UITextFieldShouldChange가 두 번 호출됨 (UITextFieldShouldChange being called twice)

Mapview Xcode에서 위치 업데이트 (Update Location in Mapview Xcode)

MKMapView 폐색이 주석을 제거합니까? (Does MKMapView occlusion cull it's annotations?)

값이 없는 경우 HTML5 로컬 저장소 개체는 무엇을 반환합니까? (What does the HTML5 Local Storage object return if there is no value?)

MKMapView에서 사용자 위치를 찾는 데 문제가 있음 (Problems Trying to Find User Location in MKMapView)

MKMapView에 주석을 추가할 때 백그라운드에서 앱 충돌 (Crashes app in background when adding annotation on MKMapView)

모든 프로젝트 Swift 5에서 1개의 MapView를 공유하는 방법 (How to Share 1 MapView in all Project Swift 5)







코멘트