gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 07:42:58 27 4
gpt4 key购买 nike

如果 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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com