1

I am trying to get the geolocation of the iOS device. I am able to get the coordinates of the present location using CoreLocation framework.

But the problem is I have to handle the scenario when location services has been disabled from device settings. In that case, I have to redirect the user to settings from within my app as per the requirement.

I know that I can do this using the below scheme prior to iOS 5.1

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];

But, how to handle this in this newer releases. I am stuck with this since a long time and no solution yet. Please advise.

Rashmi Ranjan mallick
  • 6,390
  • 8
  • 42
  • 59

2 Answers2

1

You should call: [CLLocationManager locationServicesEnabled]

As it states here:

http://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLLocationManager_Class/CLLocationManager/CLLocationManager.html

Gonzalo Aune
  • 131
  • 3
  • 10
1

@Rashmi - You might be getting some trouble some where else.

CoreLocation Framework automatically detects if the Location Settings are disabled from the Device via generating an alert and take you automatically to the device settings.I had verified this in iOS7, iOS6 devices.

Moreover, I Googled and found that this is the only way to open setting from the app and that matches with you have written.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];

You can also follow this URL for reference Open Device Settings from the app

For Core Location, You can see this demo CoreLocation

Community
  • 1
  • 1
Sumit Sharma
  • 1,847
  • 1
  • 22
  • 25
  • … My problem is that **[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]]** works only with iOS 5 os version. How to handle the same in newer versions? – Rashmi Ranjan mallick Nov 25 '13 at 15:46
  • AFAIK it is no longer possible to redirect the user to the Settings. The best you can do is provide a message with a text explaining to the user what to do. – Taum Nov 25 '13 at 15:53
  • 1
    @RashmiRanjanmallick Can you show the code snippet on pastie.org so that I can see the error. More over I had checked that Core Location framework automatically handles this and redirect you to the device settings – Sumit Sharma Nov 25 '13 at 15:54
  • @Taum When you check Google Apps or any location based App and your device Location Services are off, than you are automatically redirected to the Location Services(Settings). – Sumit Sharma Nov 25 '13 at 16:02
  • The default popup that appears when you first instantiate CLLocationManager does have a button to redirect to Settings, yes. What I meant was that it is not possible to do the same from a popup that you display yourself. It is also not possible to choose when the default popup is displayed, as I believe it's only shown the first time you instantiate CLLocationManager. – Taum Nov 25 '13 at 16:08
  • @Sumit: Thanks for your suggestion. I verified just now and it actually gives an option to redirect to settings app if settings is disabled. But I have one more doubt… when does iOS throws that alert when settings is disabled? – Rashmi Ranjan mallick Nov 25 '13 at 16:27
  • @RashmiRanjanmallick- You're right, This code is not working .I had checked this on simulator as well as on device. Might be they have changed some internal settings. Although if we are going to open browser using the same - it is working fine. – Sumit Sharma Nov 25 '13 at 17:18