2012-02-01 60 views

回答

86

例如:

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

而且

[font=] 
About — prefs:root=General&path=About 
Accessibility — prefs:root=General&path=ACCESSIBILITY 
Airplane Mode On — prefs:root=AIRPLANE_MODE 
Auto-Lock — prefs:root=General&path=AUTOLOCK 
Brightness — prefs:root=Brightness 
Bluetooth — prefs:root=General&path=Bluetooth 
Date & Time — prefs:root=General&path=DATE_AND_TIME 
FaceTime — prefs:root=FACETIME 
General — prefs:root=General 
Keyboard — prefs:root=General&path=Keyboard 
iCloud — prefs:root=CASTLE 
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP 
International — prefs:root=General&path=INTERNATIONAL 
Location Services — prefs:root=LOCATION_SERVICES 
Music — prefs:root=MUSIC 
Music Equalizer — prefs:root=MUSIC&path=EQ 
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit 
Network — prefs:root=General&path=Network 
Nike + iPod — prefs:root=NIKE_PLUS_IPOD 
Notes — prefs:root=NOTES 
Notification — prefs:root=NOTIFICATIONS_ID 
Phone — prefs:root=Phone 
Photos — prefs:root=Photos 
Profile — prefs:root=General&path=ManagedConfigurationList 
Reset — prefs:root=General&path=Reset 
Safari — prefs:root=Safari 
Siri — prefs:root=General&path=Assistant 
Sounds — prefs:root=Sounds 
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK 
Store — prefs:root=STORE 
Twitter — prefs:root=TWITTER 
Usage — prefs:root=General&path=USAGE 
VPN — prefs:root=General&path=Network/VPN 
Wallpaper — prefs:root=Wallpaper 
Wi-Fi — prefs:root=WIFI` 
prefs:root=INTERNET_TETHERING 
+0

我是测试这一点,并意识到它只是工作在ios 5.我在iPhone 3G上进行测试,而不是S。我知道它的老哈哈,有没有iOS 4的方法?还是仅限于支持iOS 5多任务的设备? – 2012-02-01 08:09:19

+1

是的,它只适用于ios 5. – 2012-02-01 08:16:45

+0

是公共API吗? – Undo 2013-04-28 21:57:51

6

在iOS5中及以上...

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General"]]; 
+0

将苹果批准开放设置的这种方式应用程序吗? – Lukas 2012-12-03 08:49:50

+1

不工作了:( – Yoga 2013-12-05 06:33:01

+0

工程确定 - 但你需要设置你的URL类型开首选项:http://i.stack.imgur.com/Nq6qQ.png – 2016-09-05 19:24:33

26

打开设置应用程序是只能从iOS版8.因此,使用下面的代码...

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]]; 
} 
} 
+0

是否可以转到设置应用程序的常规顶层,而不是您的应用程序的设置选项? – zonabi 2015-06-03 20:46:22

+1

没有@zonabi,iOS SDK没有提供任何选项。 – 2015-06-04 07:33:27

1

它适用于iOS8上+还,但我们需要改变一些东西

NSURL*url=[NSURL URLWithString:@"prefs:root=WIFI"]; 
if([[UIApplication sharedApplication] canOpenURL:url]){ 
    [[UIApplication sharedApplication] openURL:url]; 
}