提问,关于如何启动一个App的问题

大家好,

小弟最近遇到一个需要从外部启动自己App的问题,搜索了论坛发现可以使用dlopen来做,代码如下:

int (*openApp)(CFStringRef, Boolean);
void *hndl = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_LAZY);
openApp = (int(*)(CFStringRef, Boolean)) dlsym(hndl, "SBSLaunchApplicationWithIdentifier");
openApp(CFSTR("com.xxxxx.xxxxx"), FALSE);
dlclose(hndl);

编译报main.mm:9:112: error: use of undeclared identifier ‘RTLD_LAZY’,于是我就导入了头文件

#include <dlfcn.h>

结果又报Unsupported architecture

我尝试了7.1 、 8.4 、9.2三种SDK,都是报这个错误,求大家指点一下??

报这个错的话,貌似是无伤大雅的;
你把完整的编译报错贴上来看看

谢狗神,完事的报错输出如下:

Making all for tool rootdaemond...
In file included from main.mm:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/usr/include/dlfcn.h:37:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS9.2.sdk/usr/include/sys/cdefs.h:707:2: error: 
      Unsupported architecture
#error Unsupported architecture
 ^
1 error generated.
 Compiling main.mm...
 Linking tool rootdaemond...
 Stripping rootdaemond...
 Signing rootdaemond...
Making stage for tool rootdaemond...
dm.pl: building package `com.iosre.rootdaemond:iphoneos-arm' in `./com.iosre.rootdaemond_1.0-15_iphoneos-arm.deb'
xiongzhend@xiongzhenddeMacBook-Pro:~/Code/rootdaemond$ make package
Making all for tool rootdaemond...
 Compiling main.mm...
main.mm:9:112: error: use of undeclared identifier 'RTLD_LAZY'
    void *hndl = dlopen("/System/Library/PrivateFrameworks/SpringBoardServices.framework/SpringBoardServices", RTLD_...
                                                                                                               ^
1 error generated.
make[2]: *** [obj/main.mm.14876ef0.o] Error 1
make[1]: *** [internal-tool-all_] Error 2
make: *** [rootdaemond.all.tool.variables] Error 2

怎么还会报这个错呢?

如果我不加头文件的话就会报

#include <dlfcn.h>

但加了就说Unsupported architecture

加了之后报的完整错贴一下

[xiongzhend@xiongzhenddeMacBook-Pro:~/Code/rootdaemond$ make package
Making all for tool rootdaemond...
In file included from main.mm:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/usr/include/dlfcn.h:37:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS7.1.sdk/usr/include/sys/cdefs.h:655:2: error: 
      Unsupported architecture
#error Unsupported architecture
 ^
1 error generated.
 Compiling main.mm...
 Linking tool rootdaemond...
 Stripping rootdaemond...
 Signing rootdaemond...
Making stage for tool rootdaemond...
dm.pl: building package `com.iosre.rootdaemond:iphoneos-arm' in `./com.iosre.rootdaemond_1.0-12_iphoneos-arm.deb'

好像最后还是生成了.deb文件,但如果我把这个deb安装到手机上,再用iOSRERootDaemonTester去调用这个openApp的方法,是没有任何反应的,所以是否可以认为编译是不成功的?

编译成功

运行之后没有达到自己想要的效果

是两码事;我猜测是启动其他App,需要一定的entitlements

我理解为是给App加上Entitlements,而不是theos生成的tool吧?

我用ldid已经加上了,但是还是没启动App,验证如下:

ZHENde-iPhone5:/var/mobile/Containers/Bundle/Application/6962F13B-0915-4240-871E-7F55C4573B1A/DeamonDemo.app root# ldid -e DeamonDemo 
<?xml version="1.0" encoding="UTF-8"?>
<!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>ZHENde-iPhone5:/var/mobile/Containers/Bundle/Application/6962F13B-0915-4240-871E-7F55C4573B1A/DeamonDemo.app root#

但是,App无法再启动了,一启动就闪退,好消息是我确实可以通过notify把它给启动了,只是结果 一样,启动即闪退

成功了,造福一下后来人吧,流程如下:

其实理解错了,entitlements不是签名在App,而是写在tool的MakeFile里面

XXXX_CODESIGN_FLAGS=-SEntitlements.xml

就这句!!

如果给App签名了就会导致闪退,和论坛里面另一个人的日志显示是一样的,这个暂时不知道怎么处理,不过已经非常开心了,搞了两天了!