Info.plist 增加一条 NSLocationWhenInUseUsageDescription-String-提示信息
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
self.checkLocationAuthorizationStatus()
}
func checkLocationAuthorizationStatus() {
if CLLocationManager.authorizationStatus() == .AuthorizedWhenInUse {
self.mapView.showsUserLocation = true //使用前需要进行授权检查
} else {
self.locationManager.requestWhenInUseAuthorization()
}
}
网友评论