我无法调用MKMapView
委托方法didUpdateUserLocation
。Swift + didUpdateUserLocation没有被调用
我做了什么至今:
添加框架
MapKit.framwork
项目进口框架中的视图控制器通过
import MapKit
线添加键plist文件
<key>NSLocationAlwaysUsageDescription</key> <true/>
012在视图控制器
代码
新增委托didUpdateUserLocation
方法来检查位置更新或没有,但从来没有所谓。
// MARK: - MapView delegate methods
func mapView(mapView: MKMapView!, regionDidChangeAnimated animated: Bool) {
// Calling...
}
func mapView(mapView: MKMapView!, didUpdateUserLocation userLocation: MKUserLocation!) {
// Not getting called
}
// MARK: - View lifeCycle methods
override func viewDidLoad() {
super.viewDidLoad()
var locationManager = CLLocationManager()
locationManager.delegate = self
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.requestWhenInUseAuthorization()
locationManager.startUpdatingLocation()
self.mapView.delegate = self
self.mapView.showsUserLocation = true
self.mapView.pitchEnabled = true
self.mapView.showsBuildings = true
}
我已经使用模拟器和更改模拟器自定义位置来检查它是否被调用?方法regionDidChangeAnimated
被称为完美!
同样的事情适用于iOS7。 Swift地图位置更新还需要做些什么?
编辑:的plist键
也许可警报不会提示。
关键'NSLocationAlwaysUsageDescription'的'value'必须是文本,即系统请求使用位置服务许可时提示用户的问题。 – zisoft 2014-12-03 10:31:19