ros*_*ose 4 mkmapview cllocation ios swift ios9
我为mapView suing swift写了一个简单的例子,但是我得到了打印 Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
我将mapView添加到viewController并开始定位.我requestWhenInUseAuthorization()之前也打过电话startUpdatingLocation()
我设置了Info.plist
现在我同时设置NSLocationAlwaysUsageDescription和NSLocationWhenInUseUsageDescription,这是行不通的.

Tere是我的代码,出了什么问题?
class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate {
var locationManager: CLLocationManager?
var mapView: MKMapView?
override func viewDidLoad() {
super.viewDidLoad()
let locationManager = CLLocationManager()
locationManager.desiredAccuracy = kCLLocationAccuracyBest
locationManager.distanceFilter = 10
locationManager.delegate = self
locationManager.pausesLocationUpdatesAutomatically = true
if CLLocationManager.locationServicesEnabled() {
let status: CLAuthorizationStatus = CLLocationManager.authorizationStatus()
if status == CLAuthorizationStatus.NotDetermined {
if #available(iOS 8.0, *) {
locationManager.requestWhenInUseAuthorization()
}
}
locationManager.startUpdatingLocation()
self.locationManager = locationManager
} else {
print("locationServices disenabled")
}
let mapview = MKMapView(frame: self.view.bounds)
mapview.mapType = .Standard
mapview.showsUserLocation = true
mapview.delegate = self
self.mapView = mapview
self.view.addSubview(mapview)
}
}
Run Code Online (Sandbox Code Playgroud)
正如警告所说,你错过了两个必需的字符串中的一个进入你的plist
NSLocationAlwaysUsageDescription or NSLocationWhenInUseUsageDescription
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4643 次 |
| 最近记录: |