is it possible to open Settings App using openURL?

I know an app can launch other apps by using this code: [[UIApplication sharedApplication] openURL:appUrl];. And I know the scheme of URL to open safari and mail, but I did some searches and found nothing about the scheme of settings.app.


Solution 1:

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.

Solution 2:

You can use this in iOS versions 5.0 - 5.0.1. It was then deprecated in iOS 5.1.

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

Solution 3:

Opening settings apps programmatically is possible only from iOS 8. So, use the following code from http://code-ios.blogspot.in/2014/10/opening-settings-app-from-another-app.html

if([CLLocationManager locationServicesEnabled]&&
   [CLLocationManager authorizationStatus] != kCLAuthorizationStatusDenied)
{
  //...Location service is enabled
}
else
{
    if([[[UIDevice currentDevice] systemVersion] floatValue]<8.0)
    {
    UIAlertView* curr1=[[UIAlertView alloc] initWithTitle:@"This app does not have access to Location service" message:@"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [curr1 show];
    }
    else
    {
        UIAlertView* curr2=[[UIAlertView alloc] initWithTitle:@"This app does not have access to Location service" message:@"You can enable access in Settings->Privacy->Location->Location Services" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Settings", nil];
        curr2.tag=121;
        [curr2 show];
    }
}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
 NSLog(@"buttonIndex:%d",buttonIndex);

   if (alertView.tag == 121 && buttonIndex == 1)
 {
  //code for opening settings app in iOS 8
   [[UIApplication sharedApplication] openURL:[NSURL  URLWithString:UIApplicationOpenSettingsURLString]];
 }
}

Solution 4:

Swift 4 version:

if let url = URL(string: UIApplicationOpenSettingsURLString) {
    UIApplication.shared.openURL(url)
}