I am not able to call MKMapView
delegate method didUpdateUserLocation
.
What I did so far:
Add framework
MapKit.framwork
in projectImport framework in view controller by
import MapKit
lineAdd key in plist file
<key>NSLocationAlwaysUsageDescription</key> <true/>
Code in view controller
Added delegate didUpdateUserLocation
method to check location is updated or not but never called.
// 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
}
I have used simulator and change simulator custom location to check whether it is called or not? The method regionDidChangeAnimated
is called perfectly!.
The same thing works for iOS7. what additional effort is remains for Swift map location update?
Edit: Plist keys
Also permission alert not prompted.
CLLocationManager
.locationManager(_:didChangeAuthorizationStatus:)
delegate method called, before.startUpdatingLocation()
andshowsUserLocation = true
.NSLocationWhenInUseUsageDescription
value type is String.Try: