Build a Cordova app for iOS using Parallels

This article shows how you can build hybrid apps using Apache Cordova in Visual Studio and deploy them to iOS using Parallels. To accomplish this, you’ll need the following:

Any Mac that can run Mavericks or Yosemite should work with Parallels and Visual Studio, such as a 2013 MacBook Pro.

Configure Parallels

To install Parallels and Windows 8 on your Mac, follow the instructions that come with Parallels. Once you’ve installed Parallels and Windows 8, consider whether you should give your VM extra RAM and storage space, because the default values might not be sufficient. The following illustration shows some example settings in Parallels.

Parallels configuration settings

In the environment we tested, we gave the VM 2 CPUS and 3 GB RAM with 8 GB RAM on the Mac. This seemed to provide good performance for Windows while still leaving plenty of memory for OS X as well.

Important

Cordova is not designed to run off of network shares and Windows will not allow you to install a Windows app from a file share. For this reason, you either need to uncheck the Shared Profile option in your VM configuration (which causes your Documents folder to originate from a share) or choose a location for your app that is on disk that is local to your VM.

Set up Node.js with vs-mda-remote

Once you’ve got Parallels up and running, you’re ready to set up your Mac. First you need to install Node.js on OS X. Follow the directions at http://nodejs.org to install it.

Once Node.js is installed, get the vs-mda-remote agent. The remote agent allows Visual Studio to communicate with OS X and use your Mac as a build service. You can install vs-mda-remote by opening the Terminal App on your Mac and typing the following command:

sudo npm install -g vs-mda-remote

The preceding command installs the vs-mda-remote agent for all users of Node.js on your Mac. It will also install ios-sim, which is a dependency (we will use ios-sim later). If you don't want to allow others to use the vs-mda-remote agent, you can drop the –g flag from the command to install the agent for the current user.

Important

If Node.js displays error messages, you may need to start Xcode first and accept one or more license agreements. Once you do that, re-run the preceding command.

Make sure you have Parallels running. With vs-mda-remote installed, start the agent by typing the following command in the Terminal App.

vs-mda-remote

Note

By default, your iOS builds will show up in ~/remote_builds/.

When you run vs-mda-remote for the first time, the agent creates some security certificates and you should see something that looks similar to the following illustration.

Output when your first start the remote agent

You’ll need to use the PIN when you configure the agent in Visual Studio. The vs-mda-remote agent is now up and running. Leave the Terminal App open.

Get the IP address on your Mac

With Parallels running, the most reliable way to connect from Parallels to the Mac side is to use one of the vnic IP addresses because it generally won’t change between restarts. You can get these IP addresses by going to Terminal App and typing the following command:

ifconfig

The results should look similar to the following.

ifconfig command in the Terminal App

Either of the vnic IP addresses will work. With vs-mda-remote running and a vnic IP address ready to use, you can open Visual Studio in Parallels and start building on the Mac.

Configure Visual Studio to use vs-mda-remote

With Visual Studio open in Parallels, choose Tools, then Options. Open Tools for Apache Cordova, and then choose Remote Agent Configuration. Make the following changes to the remote agent settings.

  • Set Enable remote iOS processing to True.

  • Set Host to one of the vnic IP addresses your obtained previously.

  • Use the default Port setting of 3000.

  • Set Security PIN to the PIN displayed when you first ran vs-mda-remote.

Configuring the remote agent in Visual Studio

Note

If you don’t see Tools for Apache Cordova in the Options dialog box, then you may need to install the tools. Use the link at the beginning of this article to get the tools. (If the tools are already installed, try selecting the Show all settings checkbox if it is present at the bottom of the Options dialog box.)

If time expires on your security PIN, you may need to regenerate your certificates again. For more information, see Generate a new security PIN.

Build your project for iOS

Next, make sure that your project is set to build for iOS. If you don't see the Solutions Platforms list on your debug toolbar, you can show it by choosing the dropdown arrow at the right of the debug toolbar as shown in the following illustration.

Selecting a platform for deployment

Select iOS in Solution Platforms list. Then select the device you want to build for in the Debug Target list, such as Simulator – iPhone 5.

Selecting the iOS Simulator

After you select the device you want, choose the start debugging button (green right arrow). Visual Studio builds your project, handing off some of the build tasks to vs-mda-remote. Once the build completes, vs-mda-remote starts the simulator and loads your app.

iOS Simulator

Now you have a working hybrid mobile app development environment for iOS using Visual Studio and Parallels. You can develop your Cordova app and easily test it in iOS.

In later development sessions following a shutdown, you will need to restart vs-mda-remote. As described previously, just open the Terminal App in OS X and type the following on the command line:

vs-mda-remote 

With that, good luck, and happy travels developing your next mobile app!

Download the toolsGet the Visual Studio Tools for Apache Cordova or learn more