简体   繁体   中英

iOS CoreLocation: How to handle programmatically if location services are disabled from device settings

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 - 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

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