转载 2015年07月06日 18:37:39

While Apple doesn’t provide an “official” way to launch an app in the iOS Simulator from the command line, there’s a few private tricks we can employ. First, the iOS Simulator app itself is located in:


But running that will only bring up the simulator in the last state it was in. How do we install an application in there and then run it automatically like Xcode does?

The trick is in the private iPhoneSimulatorRemoteClient.framework.
Now before you freak out, don’t worry! This isn’t something you compile your app against and submit to the store. This is a framework that we can use on our local machines to control the simulator just like Xcode does. The best part is, all the work of hooking
into it has been done for us!

There are two command line utilities I’ve seen that do this best. I used to useiphonesim and
it works great. But I recently switched to WaxSim since
it also records video of the simulator in motion. They both are functionally equivalent and small enough to understand. It’s your call, but I recommend the later.1


First, we need to pull down the WaxSim source and install it. Run the following:

git clone
cd WaxSim
xcodebuild install DSTROOT=/

Now, you have the waxsim binary in /usr/local/bin which
should already be on your path. You can now invoke your application in the simulator like this:

waxsim [application path]

So, where is your application path? That depends on how you build it! First, we’ll need to do a quick walkthrough about building Xcode projects from the command line.

cd into your iOS application’s project directory (the one with the
Xcode project file). Then, invoke the xcodebuild command like so:

xcodebuild -sdk iphonesimulator5.0 \
           -arch i386 \
           install DSTROOT=/tmp/MyApp

For most projects, this command will work just fine. However, if you have an explicit workspace set up, you’ll need to use man
 to learn how to teach thexcodebuild binary to interpret
your setup. There’s a lot of good stuff in there about how to specify whether to build for the simulator or device, too.

The DSTROOT environment variable on the command above is the most important
part. DSTROOT is used by Xcode when run with the “install” build action
to figure out where to put the results. We’re specifying /tmp/MyApp explicitly
so that we know where the resulting application bundle will be to hand in to waxsim.

Once the xcodebuild command completes, you should now have an *.app
bundle in /tmp/MyApp/Applications/[YourAppName].app. Of course, subtitute
your own application name in the path. Invoke waxsim and you’re up
and running:

waxsim /tmp/MyApp/Applications/[YourAppName].app

This runs the iPhone simulator with the latest SDK that waxsim is aware
of. Usewaxsim -h to find out other options like running the iPad simulator
or other using other available SDKs.

You can also record a low resolution video of the simulator like so

waxsim -v /tmp/MyApp/Applications/[YourAppName].app

And now you’ll have in the current directory. It’s a pretty
low res and stuttery video, probably not something you’d use for a promotional demo, but it’s a nice feature if you need to review results of automated testing workflows.


So, for completeness sake, here’s a shell script that you can modify to build and run your application:


# Tell bash to abort the script if any error happens
set -e


xcodebuild -sdk iphonesimulator5.0 \
           -arch i386 \
           install DSTROOT="$DSTROOT"

waxsim "$DSTROOT"/Applications/"$APPNAME".app

Drop this in your project directory and tweak to taste.


So, there you have it. We’ve built the waxsim binary, learned briefly
how to build with xcodebuild, and learned how to launch your application
in the iOS simulator on demand and from the command line. Vive la Unix!


While Apple doesn’t provide an “official” way to launch an app in the iOS Simulator from the command...
  • love_monkey
  • love_monkey
  • 2014年07月17日 13:41
  • 3660


好在看了下 XCode6 之后提供了xctool这个工具,可以做到这些事情: 启动一个模拟器把app安装到启动好的模拟器上面从模拟器上卸载指定的app 赞!就是我做的事情嘛: 根...
  • tianshats
  • tianshats
  • 2016年07月04日 13:34
  • 907


大家都知道,应用安装到模拟器上,运行应用直接读取你的应用数据。甚至能够通过修改模拟器的经纬度来达到模拟使用应用的人运行轨迹的效果,进而达到欺骗那些通过GPS计算距离的应用,来骗取钱财的效果。 对这种...
  • jia12216
  • jia12216
  • 2016年01月18日 15:56
  • 6389

iOS 把模拟器中的的.app文件给其他小伙伴,放到他们的模拟器中运行的方法

现在我想把我们做的App 交给其他的小伙伴放到模拟器中运行的方法。。 首先自己重新 Check out 一套代码,然后运行,这样模拟器中就会有该程序对应的App  文件,如图...
  • willhanweijia
  • willhanweijia
  • 2015年11月12日 13:40
  • 1154

给iOS 模拟器“安装”app文件

刚刚接触iOS的时候,我就一直很好奇,模拟器上面能不能直接安装app呢?如果可以,我们就直接在模拟器上面聊QQ和微信了。直到昨天和朋友们聊到了这个话题,没有想到还真的可以给模拟器“安装”app! 一...
  • liangliang2727
  • liangliang2727
  • 2016年11月15日 17:22
  • 2405

iOS 模拟器安装 .app 方法

iOS Simulator,是在Mac环境下开发iOS平台的程序时候,可以使用的辅助工具。iOS Simulator 是Xcode的一部分,通常在Xcode运行(或调试)应用程序时会自动启动。Xcod...
  • Htao_sir
  • Htao_sir
  • 2016年06月07日 15:31
  • 4191


不让APP在模拟器运行在特殊的需求下还是要做一个的。 首先你需要一个这样的工具类。 public class FindEmulator { // Need to check th...
  • a29208029
  • a29208029
  • 2016年03月09日 16:03
  • 3795

Android 禁止应用在模拟器上运行的实现

一种禁止应用在模拟器上运行的思路,首先要分辨出模拟器和真机,然后对模拟器的做处理。 这里提供一种分辨方法: TelephonyManager telephonyManager = (Tel...
  • a102111
  • a102111
  • 2015年09月06日 16:50
  • 5035

如何将ios app安装到模拟器

1、安装brew 打开命令行,执行以下命令: ruby -e "$(curl -fsSL
  • yinxin2745154
  • yinxin2745154
  • 2015年12月22日 15:45
  • 6341


  • tiebanshao
  • tiebanshao
  • 2015年11月13日 15:23
  • 695