iOS 6运行时头文件使用其包标识符打开应用程序[非越狱]

时间:2015-07-16 05:03:48

标签: ios objective-c runtime

我想通过使用iOS 6运行时标头方法以编程方式通过其包标识符打开应用程序。我已经在iOS 7和8中完成了这个,但我在iOS 6中找不到任何合适的方法。请指导我如何做到这一点。请记住,我正在为企业应用程序实现此功能。

iOS 7和8中的工作代码

if ([self checkOSVersion] >= 7)
{       
    Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace");
    NSObject* workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)];

    BOOL result = [[workspace performSelector:@selector(openApplicationWithBundleID:) withObject:appIdentifier] boolValue];        
} 

1 个答案:

答案 0 :(得分:1)

我认为如果不使用URL Scheme

,你将无法做到这一点
[[UIApplication sharedApplication] openUrl:[NSURL urlWithString:@"yourUrlScheme://"]];

缺点:您需要提前注册,或者知道应用程序注册的URL Scheme

您可以找到一些URL方案herehere的列表 对于其他应用,您必须提取.ipa。这是一种方法(来自that SO answer):

  

所以我在我的Mac上访问了iTunes,并在我的应用程序库中查找了“APP IN QUESTION”。

     

然后我:•右键单击“APP IN QUESTION”应用程序并选择“在Finder中显示”

     

•然后复制了“APP IN QUESTION”.ipa文件

     

•然后我重命名.ipa文件以.zip结尾(说,如果有必要,请将其设为.zip)

     

•然后我将其解压缩到一个文件夹

     

•我打开了有效负载文件夹

     

•我右键点击“”APP IN QUESTION“.app”并选择“显示包装内容”

     

•我在文本编辑器中打开了“Info.plist”文件,如免费的TextWrangler.app

     

•我搜索了“URL”并找到了以下内容:

<key>CFBundleURLTypes</key>
        <array>
            <dict>
              <key>CFBundleURLSchemes</key>
              <array>
                   <string>app-in-question</string>
                   <string>sslapp-in-question</string>
              </array>
           </dict>
        </array>
  

然后我能够成功访问Safari并输入:app-in-question://和sslapp-in-question://并且系统提示我是否要在问题中启动应用程序。

编辑:

这应该有效

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