更新:
看起来原来的/usr/bin/open 已经在 Cydia 上针对 iOS 6 进行了更新,所以我建议你先尝试一下。
原答案:
我也想念open!但是,在它为 iOS 6 更新之前,您可以构建自己的非图形应用程序(只是一个 main 程序,而不是 UIApplicationMain())并自己做同样的事情。
我将跳过解析来自 int main(int argc, char *argv[] 的命令行参数,但是一旦您知道要打开的应用程序的 Bundle Id (CFBundleIdentifier),请打开 SpringBoardServices 私有框架,并使用它来启动应用程序:
#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);
}
此代码需要com.apple.springboard.launchapplications 授权才能让您的命令行程序以mobile 用户的身份成功使用它。 See here for adding an entitlement。您的可执行文件需要一个 entitlements.xml 文件,如下所示:
<!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>
然后用签名
ldid -Sentitlements.xml MyCommandLineTool
注意:我没有测试过这个,但是this answer states that an alternative to using entitlements is to run the command as root。