I want to open location service screen programmatically to turn on service.
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"]];
}
I have tried all the above answers,it's not working on iOS11..it just opens settings page and not the app settings .. Finally this works..
UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)
Swift 4.2:
UIApplication.shared.open(URL(string:UIApplication.openSettingsURLString)!)
Refer: https://developer.apple.com/documentation/uikit/uiapplicationopensettingsurlstring?language=swift
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)
}
You can open it directly like using below code,
But first set URL Schemes
in Info.plist's URL Type Like:
Then write below line at specific event:
In Objective - C :
[[UIApplication sharedApplication] openURL:
[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
In Swift :
UIApplication.sharedApplication().openURL(NSURL(string: "prefs:root=LOCATION_SERVICES")!)
Hope this will help you.
URL(string: "App-prefs:root=LOCATION_SERVICES")
still works without problems... –
Variorum 🚨🚨
Do you want to be safe? use UIApplicationOpenSettingsURLString
, which will open the app settings, without deep-link.
Using App-prefs
your app will be rejected, as many sub comments said.
https://github.com/mauron85/cordova-plugin-background-geolocation/issues/394
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)
}
First:
Add URL
Go to Project settings --> Info --> URL Types --> Add New URL Schemes
See image below:
Second:
Use below code to open Location settings:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];
referred from: https://mcmap.net/q/117755/-opening-the-settings-app-from-another-app
App-Prefs:root=Privacy&path=LOCATION
worked for me. –
Premium 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.
startUpdatingLocation()
showed me a standard dialog to navigate to the location service settings. And it navigated into the system wide location service settings! But it did that only the first time I called it. Any idea on this? –
Kaolack This solution works for me, but I didn't know App Store will reject my app or not
if let bundleId = Bundle.main.bundleIdentifier,
let url = URL(string: "\(UIApplication.openSettingsURLString)&root=Privacy&path=LOCATION/\(bundleId)") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
Actually there's much simpler solution to that. It'll show your app settings with loction services/camera access, etc.:
func showUserSettings() {
guard let urlGeneral = URL(string: UIApplicationOpenSettingsURLString) else {
return
}
UIApplication.shared.open(urlGeneral)
}
Eureka: Forget about URLs. Use the method requestWhenInUseAuthorization
from the CLLocationManager
code to open the native prompt message. This is what Tinder and other apps do. Took me a while to figure it out.
This will open a prompt to take you EXACTLY to the Location Services screen:
let locationManager = CLLocationManager()
locationManager.requestWhenInUseAuthorization()
After adding prefs as a url type, use the following code to go directly to the location settings of an application.
if let url = URL(string: "App-prefs:root=LOCATION_SERVICES") {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
© 2022 - 2024 — McMap. All rights reserved.