2009-07-07 83 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) 
} 
相關問題