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

由网友(所遇皆良人)分享简介: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...

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.

阅读全文

相关推荐

最新文章