2009-07-07 85 views
22

我知道一个应用程序可以使用此代码启动其他应用程序:[[UIApplication sharedApplication] openURL:appUrl];。我知道打开safari和邮件的URL方案,但是我做了一些搜索,并没有发现任何关于settings.app的方案。是否可以使用openURL打开设置应用程序?

+1

可能重复的[打开设置应用从另一个应用程序](http://stackoverflow.com/questions/5655674/opening-the-settings-app-from-another-app) – Flexo 2011-10-15 21:08:40

+0

我认为[这个问题](http://stackoverflow.com/questions/377102 /怎么办-I-开放的 - 设置 - 应用程序 - FR om-my-application)回答它。 – 2009-07-07 05:12:29

+1

检查答案:http://stackoverflow.com/questions/28152526/how-do-i-open-phone-settings-when-a-button-is-clicked-ios/34024467#34024467 – 2015-12-01 16:00:33

回答

16

您可以在iOS 5.0 - 5.0.1版本中使用它。它在iOS 5.1中被弃用。

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

不再适用于iOS 5.1。 – mrueg 2012-03-31 16:31:20

31

您可以打开设置应用程序试试这个(只能从iOS8上起)。

如果您使用的斯威夫特:

UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)) 

如果您正在使用的Objective-C

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

较低的其他版本(小于iOS8上)其不可能以编程方式打开设置应用。

3

开放设置应用程式编程是可能仅从的iOS 8.所以,从使用以下代码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]]; 
} 
} 
0

夫特4版本:的

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