ios - 在 iPhone 中以编程方式从另一个应用程序打开“设置”应用程序

标签 ios iphone gps settings

如果 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);
    }

最佳答案

好消息:

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

如果您使用的是 Swift 3.0:

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

如果您使用的是 Objective-C:

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

对于其他较低版本(低于 iOS8),无法以编程方式打开设置应用。

关于ios - 在 iPhone 中以编程方式从另一个应用程序打开“设置”应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20840089/

相关文章:

iphone 开发 : how to put a UIView over UITableView

iphone - AVAudioSession endInterruption() 返回 NSOSStatusErrorDomain

java - Android Intent启动时获取GPS

blackberry - 如何以编程方式关闭黑莓上的 GPS

android - 谷歌导航(Android 1.6) Intent 回调

ios - swift UINib 错误

iphone - 批量插入到 iPhone 上的 sqlite 数据库中

ios - 重新加载数据后表格 View 选择行无限循环

ios - 只有单个 uitableview 单元格可以拖动和重新排序

ios - 为通用iOS应用制作图像需要什么分辨率?