JetBrains AppCode如何启动iOS模拟器



我刚刚看了JetBrains的应用程序代码IDE,它似乎能够启动iOS模拟器并在其中运行应用程序。

当我不得不自动化项目的部署时,我不得不求助于Applescript和GUI自动化。

他们似乎在使用一种名为"simlauncher"的封闭工具。我想知道它背后的魔力是什么。

更新:

  1. 在查看活动监视器时,我看到osascript是在模拟器启动之前从simlauncher启动的。会不会又是Applescript?我认为iOS Simulator.app无法编写脚本
  2. iOS模拟器似乎是由launchd发起的,所以simlauncher肯定不是自己发起的。此外,simlauncher只停留到实际应用程序在模拟器中运行为止。他们可能在投票支持它
  3. 对于设备构建,他们使用的是AMDeviceService,这可能是苹果移动设备服务的一个版本。这是越狱SDK中的技术吗

来自"ps"输出的关于模拟器的更多信息:

plumenator 26404  12.9  1.3   290172  52772   ??  SX    8:56PM   0:03.62 /Users/plumenator/Library/Application Support/iPhone Simulator/4.3.2/Applications/817A280D-1F74-4755-B848-B04EC8A24ADA/xxx.app/xxx
plumenator 26395   2.3  0.3   444208  13560   ??  S     8:56PM   0:00.72 /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/iPhone Simulator -SessionOnLaunch NO
plumenator 26402   1.4  0.8   318320  33052   ??  Us    8:56PM   0:00.86 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/System/Library/CoreServices/SpringBoard.app/SpringBoard -SBDisableAutoDim YES -SBAutoLockTime -1 -SBAutoDimTime -1 -SBDontLockAfterCrash YES -SBDidShowReorderText YES -SBFakeBars YES -SBDontAnimateAppleDown YES -SBEnableDoubleHeightToggling YES
plumenator 26406   0.0  0.4  2466496  15792   ??  Ss    8:56PM   0:00.16 /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/libexec/gdb/gdb-i386-apple-darwin --arch i386 --interp=mi1 -q
plumenator 26401   0.0  0.1   106584   5688   ??  S     8:56PM   0:00.30 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/libexec/lsd
plumenator 26400   0.0  0.1   105228   4204   ??  S     8:56PM   0:00.13 /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/libexec/installd -t 30
plumenator 26399   0.0  0.3   223488  11464   ??  Ss    8:56PM   0:00.15 /Developer/Platforms/iPhoneSimulator.platform/Developer/Applications/iPhone Simulator.app/Contents/MacOS/SimulatorBridge 26395

现在我想这只是一个根据pid对命令进行排序并执行它们的问题。:-)

不过有个问题。所有这些二进制文件都指向模拟器平台根目录中的dylib。当我直接运行它们时,它们会在'/'中查找。

有没有办法在运行命令之前设置dylib的路径?这看起来很有希望:http://sacredsoftware.net/svn/misc/StemLibProjects/eaglshell/tags/2.1.0/Makefile

https://github.com/BlueFrogGaming/icuke也有很好的信息。

AppCode使用了一个特殊的包装器来实现这一点,您在其控制台中注意到了这一点:

/Applications/AppCode-108.379.app/bin/simlauncher 4.3 debug iphone <PATH_TO_APP> <STDOUT> <STDERR>

simlauncher是一个没有文档记录/不友好的mach-o二进制。。。但这里有一个快速的分析:

  • 为了启动模拟器,它使用了一个私有的苹果框架(otool -L simlauncher):

    /Applications/AppCode-108.379.app/bin/simlauncher:
    @rpath/iPhoneSimulatorRemoteClient.framework/Versions/A/iPhoneSimulatorRemoteClient (compatibility version 1.0.0, current version 12.0.0)
    
  • 该框架与Xcode:捆绑在一起

    <XCODE_PATH>/Platforms/iPhoneSimulator.platform/Developer/Library/PrivateFrameworks/iPhoneSimulatorRemoteClient.framework
    
  • 并且像这样使用(class-dump simlauncher)(DTiPhoneSimulator*来自Apple Framework):

    @protocol DTiPhoneSimulatorSessionDelegate
    - (void)session:(id)arg1 didEndWithError:(id)arg2;
    - (void)session:(id)arg1 didStart:(BOOL)arg2 withError:(id)arg3;
    @end
    @interface Launcher : NSObject <DTiPhoneSimulatorSessionDelegate> {
        DTiPhoneSimulatorSession *mySession;
    }
    - (int)launch:(id)arg1 sdkVersion:(id)arg2 wait:(BOOL)arg3 device:(int)arg4 sout:(id)arg5 eout:(id)arg6 argument:(id)arg7 env:(id)arg8;
    - (void)session:(id)arg1 didEndWithError:(id)arg2;
    - (void)session:(id)arg1 didStart:(BOOL)arg2 withError:(id)arg3;
    @end
    

关于另一个二进制AMDeviceService,我只能说它使用了ProtocolBuffers,以便与MobileDevice服务通信。。。再一次,无证的东西。。。

很快得出结论,抱歉,使用JetBrains方式启动iPhoneSimulator没有简单的方法,除非逆转苹果私有/未记录的API。。。就像Jetbrains的人一样,我喜欢他们的工具,他们是顶尖的,迫不及待地想让应用程序代码成为黄金,每天都在努力:)

编辑:请参阅下面JetBrains员工的回答@JetBrains,如果有某种AMDeviceService文档来自动化一些东西,那就太好了…;)

您到底想自动化什么?安装应用程序并在模拟器或设备中启动?

关于"3":

AMDeviceService只是一些守护进程,负责与设备的任何交互。它只使用/System/Library/PrivateFrameworks/MobileDevice.framework库(它是私有的)。它不知道任何/Developer的东西(当然,如果您不打算在设备上调试的话)。

此服务在设备上部署应用程序,装载开发人员映像,浏览设备上的应用程序并启动调试服务器。

它使用基于Google协议缓冲区的协议与AppCode进行通信。不是苹果的东西。

不能100%确定这就是你的问题所在,但我可以运行一个任意的模拟器编译的应用程序,我在模拟器的桌面上(例如)有一个文件夹,在终端中有以下行(全部为一行,用适当的值替换你的系统):

/开发者/平台/iPhone模拟器.平台/开发者/应用程序/iPhone模拟器.app/Contents/MacOS/iPhone模拟器-模拟器应用程序/Users/myusername/Desktop/[字母数字应用程序目录名]/MyCompiledAppProject.app/MyCompiledProject

最后一个"MyCompiledAppProject"文件是以.app结尾的包内的实际二进制文件(您必须控制单击.app文件并选择"显示包内容"才能查看它)。如果模拟器还没有打开,这将启动模拟器。它可以很容易地打包在AppleScript中,AppleScript将新编译的应用程序位置作为文件参数,不需要打开Xcode或使用xcodebuild。

iphonesim项目为iOS应用程序提供了一个命令行启动程序。我相信它包装了你想要的东西。

我想我在哪里读到他们依靠Xcode为他们做这类事情。但它不是很具体,我不知道我在哪里读到的。也许他们正在编写Xcode来启动和部署,而不是直接编写模拟器?

电话间隙的类似项目位于https://github.com/phonegap/ios-sim.

最新更新