2

When you first time launching app with MKMapView, application shows alert with message " would like to use your current location" with options "Don't Allow" and "OK".

I need to customize this message. Also I need to know which option user selected. How can I achieve this?

UPDATED: I need to implement this on iOS 5+

user1248568
  • 621
  • 1
  • 9
  • 29

3 Answers3

3

On CLLocationManager set purpose property

From this question: Replacement for "purpose" property of CLLocationManager

The Anna Karenina answer

The replacement for the purpose property in iOS 6 is a new Info.plist key named NSLocationUsageDescription (aka "Privacy - Location Usage Description").

The key is documented in the Information Property List Key Reference but unfortunately it's not mentioned with the deprecation note of the purpose property.

However, the CLLocationManager.h does have this comment:

  • Deprecated. Set the purpose string in Info.plist using key NSLocationUsageDescription.

In your code, you could set both the key and the purpose property (but you may want to check if the location manager responds to that selector first if/when that method is actually removed in the future).

If running under iOS 6, the location manager will use the key. When running under less than iOS 6, the key will be ignored and the purpose property will be used.

Community
  • 1
  • 1
Alex Terente
  • 12,006
  • 5
  • 51
  • 71
  • 1
    purpose is deprecated in iOS 6 – jcesarmobile Apr 10 '13 at 14:00
  • MKMapView does not have CLLocationManager, how I can set `purpose` property then? Also trick with NSLocationUsageDescription works, but it does not customizing message, it just add additional text below default alert message – user1248568 Apr 10 '13 at 14:34
0

for custom message

for the message you can use the purpose property as Alex Terente said, but it has been deprecated in iOS 6

to get the option

for knowing if the user denied the permission the location Manager provides a failure delegate. the mapview uses its own location manager so: use the MKMapView function didFailToLocateUserWithError

- (void)mapView:(MKMapView *)mapView didFailToLocateUserWithError:(NSError *)error {
switch([error code]) {
                case kCLErrorDenied:{
                    //user denied
                }
                break;
            }
}

note: if you are using a CLLocationManager directly it'd be - (void)locationManager: (CLLocationManager *)manager didFailWithError: (NSError *)error;

Community
  • 1
  • 1
jcesarmobile
  • 51,328
  • 11
  • 132
  • 176
  • 2
    dont think this works!? Doesnt the map view have its own locationManager? – Daij-Djan Apr 10 '13 at 14:21
  • you were right, if he only uses the MKMapView but isn't using a CLLocation manager my answer isn't going to work, I've updated my answer, this should work. – jcesarmobile Apr 16 '13 at 08:41
  • yes, I have rewritten it show the mapview error first though because then the answer better matches the question – Daij-Djan Apr 16 '13 at 09:45
0

If you're building for iOS 6+, use the NSLocationUsageDescription in your Info.plist file. Insert this key and set its value as the description of what you will do with location information.

nevan king
  • 112,709
  • 45
  • 203
  • 241