iOS 6 Runtime headers method to open an application using its bundle identifier[Non-jailbreak]

偶尔善良 提交于 2019-12-08 13:29:16

问题


I want to open an app programmatically through its bundle identifier by using iOS 6 runtime headers method. I have done this in iOS 7 and 8 but I couldn't find any appropriate method in iOS 6. Please guide me how can I do that. Please remember that I am implementing this functionality for enterprise apps.

Working Code in iOS 7 and 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:


I don't think you'll be able to do this without using URL Scheme

[[UIApplication sharedApplication] openUrl:[NSURL urlWithString:@"yourUrlScheme://"]];

Cons : You need to register it in advance, or to know the URL Scheme registered by an app

You can find a list of some URL Scheme here or here For other apps, you'll have to extract the .ipa. Here is a way to do it (from that SO answer) :

So I went to iTunes on my mac and looked in my App Library for the "APP IN QUESTION".

I then: • Right-Clicked on the "APP IN QUESTION" app and selected “Show in Finder”

• then duplicated the "APP IN QUESTION" .ipa file

• Then I renamed the .ipa file to end in .zip instead (saying, yes make it a .zip if necessary)

• Then I unzipped it to a folder

• I opened the Payload Folder

• I right-clicked the “"APP IN QUESTION".app” and selected “Show Package Contents”

• I opened up the “Info.plist” file in a text editor like the free TextWrangler.app

• I searched for “URL” and found the following:

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

I was then able to successfully go to Safari and type in: app-in-question:// and sslapp-in-question:// and was prompted if I wanted to launch the App in Question.

EDIT:

This should work

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);


来源:https://stackoverflow.com/questions/31445692/ios-6-runtime-headers-method-to-open-an-application-using-its-bundle-identifier

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!