Reputation: 4487
How do we open Settings using the UIApplication.sharedApplication()
What URL should I pass in?
I used the UIApplicationOpenSettingsURLString
but it opens directly to the Application specific Settings page. but I would like to have it open the first level of the Settings app.
Or even better, I would like it to open directly to the page where user can enable the Location Services on their phone.
the codes below opens directly to the Application specific Settings page.
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!);
Upvotes: 5
Views: 1915
Reputation: 6092
For Xamarin.iOS developers:
UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString));
Upvotes: 0
Reputation:
You can use UIRequiresPersistentWiFi to YES
in your Info.plist
files and create alertview like facebook the user launches your app without a network connection.
To summarize the discussion here:
Step 1: There is no URL you can use to get to the root level of the Settings app.
Step 2: You can send the user to your app's section of the Settings app using UIApplicationOpenSettingsURLString
in iOS 8.
Your app can display the same alert as Facebook, which does open the root level of the Settings app, by setting UIRequiresPersistentWiFi
to YES
.
Upvotes: 2
Reputation: 82759
the answer to this questions is NO, we can't open direct Location page ,but we can open UIApplicationOpenSettingsURLString
(settings page)
try this
if let appSettings = NSURL(string: UIApplicationOpenSettingsURLString) {
UIApplication.sharedApplication().openURL(appSettings)
}
else
{
// your URL is invalid
}
for additional information
Upvotes: 4
Reputation: 3178
You can open settings apps programmatically try this(works only from iOS8 onwards).
If you are using Swift
:
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString))
If you are using Objective-C
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
For other lower versions(less than iOS8) its not possible to programatically open settings app.
Obj C:
- (void)openSettings
{
BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);
if (canOpenSettings) {
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
}
Swift:
func openSettings() {
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
}
Upvotes: 1