Call the official *Settings* app from my app on iPhone

泪湿孤枕 提交于 2019-11-27 00:18:03

As noted in the comments below, this is no longer possible in iOS version 5.1 and after.

If you are on iOS 5.0, the following applies:

This is now possible in iOS 5 using the 'prefs:' url scheme. It works from a web page or from an app.

example urls:

prefs:root=General
prefs:root=General&path=Network

sample usage:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General"]]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=Network"]]

From IOS 8 you can call the settings from within app with this:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

Slemon

It's also work in iOS version > 5.1, but you must add an URL schemes in URL types in Xcode:

Then you can use

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];

It's can open system WiFi setting now.

Other path please find in this answer: iOS Launching Settings -> Restrictions URL Scheme.

Di Wu

Bad news: As @Hlung and @jasongregori suggested, for iDevices whose OS version >= iOS 5.1 && < iOS 8.0, there is once again NO official/documented way to call the built-in Settings app from a third-party app. Period.

Calling the settings app from other app is possible only from iOS 8. So, use the following code

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

from iOS 8, you can redirect with

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

enjoy coding

Just an additional answer to add onto the one's addressing iOS8+. If you're supporting anything below 8, you should check to see if it's supported

BOOL canGoToSettings = (UIApplicationOpenSettingsURLString != NULL);
if (canGoToSettings)
{
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}

For settings in iOS 9 this is worked for me.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Settings"]];

But make sure you add a url schemes in URL types in

Info tab in app targets.

For iOS 10 you can use:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Settings"]];

It is also working on iOS 9!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!