如何在iOS中打开没有URL方案的手机应用程序



我正在进行锁屏调整。 在我的自定义锁屏视图中,有一个按钮,您可以使用它来锁定和打开本机手机应用程序。 我正在使用的IDE是iOSOpenDev。

我尝试过这些方法:

  1. 网址方案:我不想表盘显示,所以放弃了。

  2. SBSLaunchApplicationWithIdentifier. 这是最流行的方法,如下所示:

void* sbServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
int (*SBSLaunchApplicationWithIdentifier)(CFStringRef identifier, Boolean suspended) =
   dlsym(sbServices, "SBSLaunchApplicationWithIdentifier");
int result = SBSLaunchApplicationWithIdentifier((CFStringRef)bundleId, false);
dlclose(sbServices);

但是在 .xm 文件中,编译器告诉我

无法初始化类型为"int (*)(CFStringRef,布尔值)"的变量,其右值为"void *"。

我该怎么做?谢谢!

我不确定您使用的是哪个编译器会给您此错误...Apple LLVM 编译器(4.2 或 5.0)接受您显示的代码,没有问题。

但是,我认为,您应该能够通过将 dlsym() 的返回值转换为(int (*)(CFStringRef, Boolean))来修复该编译错误:

int (*SBSLaunchApplicationWithIdentifier)(CFStringRef identifier, Boolean suspended) =
   (int (*)(CFStringRef, Boolean))dlsym(sbServices, "SBSLaunchApplicationWithIdentifier");

最新更新