Edw*_*raj 35 iphone settings gps ios
如果iPhone中没有启用gps,我必须从我的应用程序打开设置应用程序.我使用了以下代码.它在iOS模拟器中运行良好,但在iPhone中不起作用.我可以知道此代码中是否有任何问题.
if (![CLLocationManager locationServicesEnabled]) {
int (*openApp)(CFStringRef, Boolean);
void *hndl = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices");
openApp = (int(*)(CFStringRef, Boolean)) dlsym(hndl, "SBSLaunchApplicationWithIdentifier");
openApp(CFSTR("com.apple.Preferences"), FALSE);
dlclose(hndl);
}
Run Code Online (Sandbox Code Playgroud)
Yat*_*B L 111
好消息 :
您可以像这样以编程方式打开设置应用程序(仅适用于iOS8以上版本).
如果您使用的是Swift 3.0:
UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!)
Run Code Online (Sandbox Code Playgroud)
如果您使用的是Objective-C:
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
Run Code Online (Sandbox Code Playgroud)
对于其他较低版本(低于iOS8),无法以编程方式打开设置应用程序.
Ale*_*ien 10
正如其他人所回答的那样,您无法从应用中打开"设置".
但是你可以解决这个问题,就像我做的那样:
输出一条消息,必须启用位置服务来解释原因,并在该消息中显示路径:
"设置 - >与隐私> LocationServices"
以编程方式打开设置应用程序只能从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]];
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
34766 次 |
| 最近记录: |