简体   繁体   中英

User location in mapView doesn't show on several simulator devices (MapKit)

I've implemented a mapView that finds the user location and displays it, but the problem is that it doesn't work on iPhone 4S, iPhone 5, iPhone 5S, and iPhone 6 Plus in the iOS simulator, only on iPhone 6. The strange thing is that it works on my real iPhone 5S device.

Could this be a simulator problem or will this happen on real devices too?

This is the warning that I receive:

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

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

What's the hard part here? Your map view cannot show the user's location until your app explicitly asks for authorization to use the user's location. The error message even shows you the methods, one of which you must call, in order to do that! How could it be any more helpful? Just do what it is telling you to do.

Note that you must not only request authorization, you must receive authorization.

I ended up solving my own question.

I just added this line of code in viewDidLoad:

 [self.locationManager requestWhenInUseAuthorization];

This was very helpful: http://nevan.net/2014/09/core-location-manager-changes-in-ios-8/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM