Unity iOS on Windows: Deploying to iPhone from within Unity Editor on Windows machine, using VMWare
Here is an aid for developing Unity iOS apps on Windows machine. Using VMWare, one can run a shell script on a local virtual machine to automate the entire process of deploying Unity apps from Editor to iPhone via USB. The process is click-and-wait basis and each build should take about 5 minutes. This article proposes some components to manage the automation.
Note: This is a “poor man’s” method and potentially wastes your resource in a long run if you could just buy a Macbook in the first place. Also, please read through and do your own research before fully committing, because there may be some hardware requirements.
Disclaimer: Running any macOS on non-Apple hardware is against the Apple EULA. Please acknowledge the risk and proceed on your own responsibility.
The shell script watches very simple timestamp files in a directory that both Windows and VM macOS have a read/write access to. Whenever Unity Editor composes a project into the folder, a C# post-process script will set a flag in the files. Then in VM, the shell script will detect the flag, build/deploy the project and fold the flag.
So, as long as the script is running on VM, user can press the “Build” button in Unity Editor and hands-free wait until iPhone opens the app automatically.
Setting up Shared Folder
Shared Folder is VMWare’s feature to access to the host file system. This folder will house and enable communication between Unity Editor and shell script.
Setting up xcodebuild
To build an XCode project via shell script, there’s a command line tool called
xcodebuild. This should come bundled with XCode app.
Setting up ios-deploy
xcodebuild doesn’t have a feature to deploy to devices, but there’s another tool called
ios-deploy to do so. Also an iPhone needs to be connected to the computer via USB and routed to VM.
- Connecting USB Devices
Setting up Unity C# Post-process Script
Static methods marked with
[PostProcessBuild]attribute are invoked whenever a build is finished. For the timestamp file’s format, the script can be something like this:
Whenever user hits the “Build” button, Unity Editor will compile the project into an XCode project, then this script will update the timestamp.
The build path must be set to inside the Shared Folder.
Setting up Shell Script
Here’s the entire script, followed by some in-depths on important lines.
The script may be set to login item so that it automatically starts running. The process can be halted it by closing the terminal window.
The Shared Folder is named
__transfer_ in the script which may be changed, as well as project name (
MyProject) and app name (
foo.app). Those names must match with build settings in Unity Editor.
By default, commands like
cp can’t access inside Shared Folder (“no such file or directory”). So, the script mounts it in the local drive prior to any other commands:
mkdir -p <target directory path>
sudo mount -t vmhgfs .host:/ <target directory path>
Also, XCode can’t build inside Shared Folder regardless of mounting. So the script works around that by copying the project to desktop and building off there.
Unity projects have a specific format in file names, so some arguments like project/target names can be hard-coded. This command will start the build, print out all the logs and save the product in
cd <project root>
xcodebuild -project Unity-iPhone.xcodeproj\
-configuration Debug build
Finally the script will deploy the build to a connected iPhone via USB:
cd <project root>/build/debug-iphoneos
ios-deploy --uninstall -- noninteractive --debug --bundle foo.app
Unity’s remote profiler feature does work, as long as Windows and iPhone are connected to the same WiFi. User can also make a use of runtime logs printed out to terminal by
With all set, user can press the “Build” button in Unity Editor and observe the shell script reacting to it as soon as Unity finishes composing the project in Shared Folder. Then the script will start building and deploying to connected iPhone. The script will go back in the main loop as soon as the app is closed or crashes on the device.
So, here’s a concept and sample code to operate an auto-build-and-deploy system of Unity iOS apps on Windows.