在我的应用程序中,我想将用户重定向到官方设置应用程序。如果可能的话,我还想直接进入“设置”应用程序中的“网络”部分。
我认为我需要的是设置应用程序的 url 方案和构造我的请求的格式。但我怀疑调用这样的官方应用程序是被禁止的。
谁能帮助我?
在我的应用程序中,我想将用户重定向到官方设置应用程序。如果可能的话,我还想直接进入“设置”应用程序中的“网络”部分。
我认为我需要的是设置应用程序的 url 方案和构造我的请求的格式。但我怀疑调用这样的官方应用程序是被禁止的。
谁能帮助我?
正如下面评论中所指出的,这在 iOS 5.1 及更高版本中不再可能。
如果您使用的是 iOS 5.0,则以下内容适用:
这现在可以在 iOS 5 中使用 'prefs:' url 方案。它适用于网页或应用程序。
示例网址:
prefs:root=General
prefs:root=General&path=Network
示例用法:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General"]]
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=Network"]]
在 IOS 8 中,您可以使用以下命令从应用程序内调用设置:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
它也适用于 iOS 版本 > 5.1,但您必须在 Xcode 中的 URL 类型中添加 URL 方案:
然后你可以使用
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=WIFI"]];
现在可以打开系统WiFi设置了。
其他路径请在此答案中找到:iOS Launching Settings -> Restrictions URL Scheme。
坏消息:正如@Hlung 和@jasongregori 建议的那样,对于操作系统版本>= iOS 5.1 && < iOS 8.0的iDevice,再次没有官方/记录的方式可以从第三方应用程序调用内置设置应用程序。时期。
只能从 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
{
if (alertView.tag == 121 && buttonIndex == 1)
{
//code for opening settings app in iOS 8
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
}
从 iOS 8 开始,您可以使用重定向
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
享受编码
只是一个额外的答案添加到一个人的地址 iOS8+。如果你支持低于 8 的任何东西,你应该检查它是否被支持
BOOL canGoToSettings = (UIApplicationOpenSettingsURLString != NULL);
if (canGoToSettings)
{
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
}
对于 iOS 9 中的设置,这对我有用。
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Settings"]];
但请确保在 URL 类型中添加 url 方案
应用程序目标中的信息选项卡。
对于 iOS 10,您可以使用:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Settings"]];
它也适用于 iOS 9!