【发布时间】:2010-11-08 14:08:30
【问题描述】:
我知道一个应用可以使用以下代码启动其他应用:[[UIApplication sharedApplication] openURL:appUrl];。而且我知道打开 safari 和邮件的 URL 方案,但是我做了一些搜索,没有发现关于 settings.app 的方案。
【问题讨论】:
-
我认为this question 回答了它。
我知道一个应用可以使用以下代码启动其他应用:[[UIApplication sharedApplication] openURL:appUrl];。而且我知道打开 safari 和邮件的 URL 方案,但是我做了一些搜索,没有发现关于 settings.app 的方案。
【问题讨论】:
Swift 4 版本:
if let url = URL(string: UIApplicationOpenSettingsURLString) {
UIApplication.shared.openURL(url)
}
【讨论】:
您可以在 iOS 版本 5.0 - 5.0.1 中使用它。然后它在 iOS 5.1 中被弃用。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
【讨论】:
只能从 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]];
}
}
【讨论】:
您可以以编程方式打开设置应用程序试试这个(仅适用于 iOS8 及以上)。
如果您使用的是 Swift:
UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString))
如果你使用的是 Objective-C
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
对于其他较低版本(低于 iOS8),无法以编程方式打开设置应用程序。
【讨论】: