0

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.

Yomo
  • 175
  • 2
  • 15

2 Answers2

0

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.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • It doesn't ask for it. It does on a real device... :/ – Yomo May 26 '15 at 00:41
  • Reset the simulator. You probably _already denied access_ - and therefore you can't get the request any longer. Either that or switch to Settings and provide access there. – matt May 26 '15 at 00:44
  • Here's working code: https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch21p761userLocationAndGeocoding/ch34p1024userLocationAndGeocoding/ViewController.swift – matt May 26 '15 at 00:46
  • I tried resetting the simulator, but it still doesn't work. Also, the iPhone 6 didn't even ask for it but showed the locaton anyway :/ – Yomo May 26 '15 at 00:56
  • See my answer here describing what your logic has to be: http://stackoverflow.com/a/30495310/341994 – matt May 28 '15 at 17:49
0

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/

Yomo
  • 175
  • 2
  • 15