iOS 8부터 지도를 사용할 때 사용자에게 위치서비스 사용 허가를 받는 방법이 바뀌었다.
그래서 이런 메시지가 뜬다.
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
iOS를 오랜만에 만지다보니 이거 검색하는데도 생각보다 오래 걸린다 -_-;;
일단 아래의 프레임웍이 필요하다.
CoreLocation.framework
MapKit.framework
import UIKit import MapKit import CoreLocation class MapViewController: UIViewController, CLLocationManagerDelegate { let locationManager = CLLocationManager() override func viewDidLoad() { super.viewDidLoad() locationManager.delegate = self; locationManager.requestWhenInUseAuthorization() } }
그리고 Info.plist 에
NSLocationWhenInUseUsageDescription
를 추가한다.
그러면
이렇게 물어보는 창이 뜬다