【问题标题】:how to open phone app without url scheme in iOS如何在 iOS 中打开没有 url 方案的手机应用程序
【发布时间】:2013-11-06 21:42:39
【问题描述】:

我正在处理锁屏调整。在我的自定义锁屏视图中,有一个按钮,您可以使用它来锁定和打开本机手机应用程序。我使用的 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 文件中,编译器会告诉我

无法使用“void *”类型的右值初始化“int (*)(CFStringRef, Boolean)”类型的变量。

我该怎么做? 谢谢!

【问题讨论】:

    标签: ios objective-c jailbreak iphone-privateapi tweak


    【解决方案1】:

    我不确定您使用的哪个编译器会出现此错误...Apple LLVM 编译器(4.2 或 5.0)可以毫无问题地接受您显示的代码。

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

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

    【讨论】:

    • 我已经添加了“(int (*)(CFStringRef, Boolean))”这几个字,但是iphone会是僵尸,你必须强制重启。
    • 该演员表将修复您在问题中发布的编译器错误。如果您的调整使您的设备崩溃,那么这是一个单独的问题。
    • 我应该添加授权文件以进行调整吗?
    • 我的代码是这样的:%new(v@:) -(void)httpButtonPressed{ int (openApp)(CFStringRef, Boolean); void sbServices = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY); openApp= (int(*)(CFStringRef, Boolean))dlsym(sbServices, "SBSLaunchApplicationWithIdentifier"); openApp(CFSTR("com.apple.Preferences"), FALSE); dlclose(sbServices); }
    • 请不要在 cmets 中发布新问题/代码。首先,您能阅读上面发布的代码吗?我不能。其次,this 问题询问如何修复编译器错误。我告诉你怎么做。请单击问题旁边的“V”标记接受此答案。如果您对此项目还有其他问题,请发布问题。关于权利,这取决于您的代码注入到哪个应用程序中。如果它运行的应用程序(例如 SpringBoard)已经有权启动应用程序,则您无需添加任何内容。如果没有,那你就有问题了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-05
    • 2023-04-03
    • 2013-04-27
    相关资源
    最近更新 更多