在iPhone中以编程方式从另一个应用打开设置应用

在iPhone中以编程方式从另一个应用打开设置应用

本文介绍了在iPhone中以编程方式从另一个应用打开设置应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果gps未在iPhone中启用,我必须从我的应用程序打开设置应用程序。我已经使用了下面的代码。它在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);
}


解决方案

好消息:



您可以像这样以编程方式打开设置应用程序(仅适用于 iOS8 以上版本)。

如果您使用Swift 3.0:
$ b $ pre $ UIApplication.shared.open(URL(字符串:UIApplicationOpenSettingsURLString)!)

如果您使用Objective-C:

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

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


I have to open settings app from my app if gps is not enabled in iPhone. I have used the following code. It works well in iOS simulator but it does not work in iPhone. May I know is there any problem in this code.

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);
    }
解决方案

Good news :

You can open settings apps programmatically like this (works only from iOS8 onwards).

If you are using Swift 3.0:

UIApplication.shared.open(URL(string: UIApplicationOpenSettingsURLString)!)

If you are using Objective-C:

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

For other lower versions (less than iOS8) its not possible to programatically open the settings app.

这篇关于在iPhone中以编程方式从另一个应用打开设置应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 00:07