2

In my app,I want to show user location in one of my UIViewController which uses MKMapKit.So when the user selects this View Controller they will be asked whether to allow or don't allow. If user selects allow, then everything fine.If they selects don't allow, then the user is never asked again to allow or not.

Actually what I want is, when user selects don't allow for the first time when they are using my app, they should be asked to select again to allow or don't allow for the next time they uses the app. So how can I achieve this? When the user selects allow for the select time (first time they clicked not allowed), then my app show the user location.

Even in some S.O question,many have suggested that the user will be promoted to allow or don't allow alert whenever they open the app.But for me its asking for the first time app used.

Please share your ideas. Thank you.

NSUserDefault
  • 1,794
  • 1
  • 17
  • 38

1 Answers1

1

If the user has turned off location services for your app the first time, you will know in your application every time you try to get their location. You can check if the user has given you permission to read their location or not. In case they haven't, they will be prompted again to enable location services for your app.

Quoting from Apple's documentation (found here)

it is recommended that you always call the locationServicesEnabled class method of CLLocationManager before attempting to start either the standard or significant-change location services. (In iOS 3.x and earlier, check the value of the locationServicesEnabled property instead.) If this class method returns YES, you can start location services as planned. If it returns NO and you attempt to start location services anyway, the system prompts the user to confirm whether location services should be reenabled. Given that location services are very likely to be disabled on purpose, the user might not welcome this prompt.

lostInTransit
  • 70,519
  • 61
  • 198
  • 274
  • Thanks for your response.My doubt is even-though if I get the user location by using locationServiceEnabled method of CLLocationManager, how can I display it in my view(ie the round blu icon).And one thing, locationServiceEnabled is deprecated now. – NSUserDefault May 16 '13 at 07:21
  • Will this allow the user to prompt again to enable location service?Could you please detail your answer how this can be achieved(may be some code)? – NSUserDefault May 16 '13 at 07:39
  • locationServicesEnabled is not deprecated! (http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html#//apple_ref/occ/clm/CLLocationManager/locationServicesEnabled) Acc to the documentation, if you start location services even if this returns a NO, the user will be prompted if they want to re-enable it. – lostInTransit May 16 '13 at 09:57
  • Hai sorry for the delay.Actually tried to access the locationServicesEnabled like this, "[CLLocationManager locationServicesEnable:YES];".But complier warning me that there is no class method +locationServiceEnabled available. Could you post some sample code. – NSUserDefault May 17 '13 at 07:03
  • This method should be used as a simple check to see whether location services are available or not "BOOL locationServ = [CLLocationManager locationServicesEnabled];" – lostInTransit May 17 '13 at 16:41
  • Thank you.Still I am not clear about it.One last question, can I able to prompt the same alert which will come for the first time when the app opened? – NSUserDefault May 18 '13 at 04:07
  • Yes. Start location services even if they are disabled for your app. The user will be asked if they want to re-enable it. Though it can be irritating (the user turned it off for a reason) – lostInTransit May 19 '13 at 10:42
  • Actually its not worked for me.I tried starting location services whenever the view appears.But it doesn't prompt an alert.Can you post some code? – NSUserDefault May 20 '13 at 04:19
  • I tried to start location service and getting this error message "Location manager denied access - kCLErrorDenied". – NSUserDefault May 20 '13 at 04:25