I want to open location service screen programmatically to turn on service.
Swift 5+
Easy Way Direct Your said application page will open
if let BUNDLE_IDENTIFIER = Bundle.main.bundleIdentifier,
let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION/\(BUNDLE_IDENTIFIER)") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Swift 4.2
Go straight to YOUR app's settings like this:
if let bundleId = Bundle.main.bundleIdentifier,
let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION/\(bundleId)")
{
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
SWIFT 4 tested:
Only way to avoid getting rejected and open Location Preferences of own app is:
if let bundleId = Bundle.main.bundleIdentifier,
let url = URL(string: "\(UIApplication.openSettingsURLString)&path=LOCATION/\(bundleId)") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Step 1: Click on project name >> target>> info >> url Types
Step 2:
-(IBAction)openSettingViewToEnableLocationService:(id)sender
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
}
If you set locationManager.startUpdatingLocation() and you have disabled on your iphone, it automatically show you an alertView with the option to open and activated location.