0

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];        
} 
shim
  • 9,289
  • 12
  • 69
  • 108
iOS_Learner
  • 159
  • 9

1 Answers1

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);
Community
  • 1
  • 1
Thibaud David
  • 496
  • 2
  • 11
  • Thanks for your help.I know the URL scheme approach already. As I mentioned its possible with private framework headers and I have done that successfully but getting an issue in iOS 6. – iOS_Learner Jul 22 '15 at 10:40
  • Can you edit your question with your working code for iOS >6 ? – Thibaud David Jul 22 '15 at 10:41
  • http://stackoverflow.com/questions/30476982/how-to-open-an-app-by-bundle-id-on-ios – iOS_Learner Jul 22 '15 at 10:43
  • I have added the working code for iOS 7 and 8. Please have a look. – iOS_Learner Jul 22 '15 at 10:46
  • Look at this, including comments, it's supposed to work on 6.x http://stackoverflow.com/a/11693879/2219009 – Thibaud David Jul 22 '15 at 10:46
  • @selector(openApplicationWithBundleID:) is available in iOS 7 and 8 runtime headers. its not available in iOS 6. so that's why I have to find some other way. – iOS_Learner Jul 22 '15 at 10:48
  • Doesn't this work ? SBApplication *app = [[objc_getClass("SBApplicationController") sharedInstance] applicationWithDisplayIdentifier:@"your.bundle.id"]; [[objc_getClass("SBUIController") sharedInstance] activateApplicationFromSwitcher: app]; – Thibaud David Jul 22 '15 at 10:53
  • 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); – iOS_Learner Jul 22 '15 at 10:55
  • Mark it as accepted answer, I edited it with working solution (You need a minimum reputation to upvote a comment) – Thibaud David Jul 22 '15 at 10:58
  • I have another question ... I am using this runtime header method to delete an app from iOS device programmtically ..........................Class LSApplicationWorkspace_class = objc_getClass("LSApplicationWorkspace"); NSObject* workspace = [LSApplicationWorkspace_class performSelector:@selector(defaultWorkspace)]; //BOOL result=[[workspace performSelector:@selector(uninstallApplication:withOptions:) withObject:bundleId withObject:@""] boolValue]; – iOS_Learner Jul 22 '15 at 11:23
  • this method is deletes and an app successfully but app crashes after deleting the app . What i found the issue with this ,,, I am not providing the second argument properly. What do you say ? – iOS_Learner Jul 22 '15 at 11:26
  • here is the Link iOS 7 runtime headers ...https://github.com/MP0w/iOS-Headers/blob/master/iOS7/Frameworks/MobileCoreServices/LSApplicationWorkspace.h – iOS_Learner Jul 22 '15 at 11:29
  • I am using this method from the header class -(_Bool)uninstallApplication:(id)arg1 withOptions:(id)arg2; – iOS_Learner Jul 22 '15 at 11:31
  • in first argument I am sending the bundle identifier and in second argument I am sending empty string . – iOS_Learner Jul 22 '15 at 11:32
  • LaunchServies: No placeholder bundle to remove for com.example.apple-samplecode.myPaintApp . this message I get on my console . – iOS_Learner Jul 22 '15 at 11:37
  • I think you should pass nil as second argument, but anyway, ask this in a new thread – Thibaud David Jul 22 '15 at 14:25
  • http://stackoverflow.com/questions/31956186/how-to-delete-an-ios-app-programatically-using-private-framework-for-non-jailbro – iOS_Learner Aug 19 '15 at 11:43