Before iOS 6.x, I used open package_id
to open a app from command line on a iOS device.
On iOS 6.x if i use this command SpringBoard crashes.
Open is available
It looks like the original /usr/bin/open
has been updated for iOS 6 on Cydia, so I recommend you try that first.
I miss open
, too! But, until it gets updated for iOS 6, you can just build your own non-graphical app (just a main
program, not a UIApplicationMain()
) and do the same thing yourself.
I'll skip over parsing command line arguments from int main(int argc, char *argv[]
, but once you know the Bundle Id (CFBundleIdentifier
) of the app you want to open, open the SpringBoardServices private framework, and use it to launch the app:
#include <dlfcn.h>
#define SBSERVPATH "/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices"
-(void) openApp: (NSString*) bundleId {
// the SpringboardServices.framework private framework can launch apps,
// so we open it dynamically and find SBSLaunchApplicationWithIdentifier()
void* sbServices = dlopen(SBSERVPATH, RTLD_LAZY);
int (*SBSLaunchApplicationWithIdentifier)(CFStringRef identifier, Boolean suspended) = dlsym(sbServices, "SBSLaunchApplicationWithIdentifier");
int result = SBSLaunchApplicationWithIdentifier((__bridge CFStringRef)bundleId, false);
dlclose(sbServices);
}
This code requires the com.apple.springboard.launchapplications
entitlement for your command line program to use it successfully, as the mobile
user. See here for adding an entitlement. You'd need an entitlements.xml file for your executable, like this:
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.springboard.launchapplications</key>
<true/>
</dict>
</plist>
And then sign it with
ldid -Sentitlements.xml MyCommandLineTool
Note: I haven't tested this, but this answer states that an alternative to using entitlements is to run the command as root.