美文网首页
iOS 9 MKMapView 定位问题

iOS 9 MKMapView 定位问题

作者: Iridescent330 | 来源:发表于2016-02-22 10:53 被阅读0次

一开始只写MKmapView初始化的时候,可以运行,但无法定位,出现如下提示:

Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.

首先我们要先在初始化MKmapView之前,初始化CLLocationManager,并且请求用户批准定位

locManager.delegate=self

locManager.requestAlwaysAuthorization()

locManager.startUpdatingLocation()

接下来要在plist文件中加入以下俩个Key

NSLocationWhenInUsageDescription // Value可以空也可以填,是自定义给用户的提示,类似 AppName is request your location

NSLocationAlwaysUsageDescription //同上

接下来再运行程序,成功定位

Happy coding : )

相关文章

网友评论

      本文标题:iOS 9 MKMapView 定位问题

      本文链接:https://www.haomeiwen.com/subject/grkbkttx.html