Looking for designers or developers for your next project?
Black Pixel offers design, development, and testing services backed by unrivaled experience.Hire Us
Back in 2013, I wrote an article about simulating locations using Xcode. It's 2016 and Apple has improved those tools to make simulating locations a bit easier and less error prone. Let's take a look at the enhancement Apple has made to its development tools and the issues that have been fixed.
GPX Files and Xcode
Xcode uses a standardized file type to simulate locations. The GPX spec outlines many different ways to define a path or set of geolocation coordinates. Xcode only uses the
<wpt> tag, so if you find a tool that generates
<trk> based GPX files, Xcode won't be able simulate your location properly.
Xcode will run through a series of
<wpt> tags as though it was a route, but it doesn't provide any mechanism to control speed or amount of time at each entry in the list of waypoints. An example of a GPX file simulating a WWDC attendee's pilgrimage to Cupertino can be found here (I hope they can swim):
<?xml version="1.0"?> <gpx version="1.1" creator="Xcode"> <wpt lat="37.783879" lon="-122.4012538"> <name>Moscone</name> </wpt> <wpt lat="37.331705" lon="-122.030237"> <name>Cupertino</name> </wpt> </gpx>
Sourcing GPX Files
Unless you're looking to string together several waypoints to simulate a user driving, Xcode can get you most of the way to having simulated locations. In the New File sheet, there is now an option to create a GPX file under the Resource section.
The default GPX file that is generated is automatically set to Cupertino. Modify the
lon attributes to your new static location and you're set to go.
Configuring a Project
Configuring a project to simulate locations is fairly straightforward. Once you have added your GPX files to your project, you can enable location simulation in your project's scheme editor or Xcode's Debug Area.
Bring up your project's scheme editor by navigating to Product -> Scheme -> Edit Scheme in menu bar. In the scheme's Run action, select the Options tab. You should see something similar to this:
The other option is to adjust it while the application is running. With your application running, open the Debug Area if it isn't already open by navigating to View -> Debug Area -> Show Debug Area in the menu bar. In the Debug Jump Bar, you will see the navigation icon next to the Debug View Hierarchy button. Clicking on it brings up a view similar to this:
The final way to simulate a location only works in the iOS Simulator. Navigating to Debug -> Location in the iOS Simulator's menu bar brings up some options for simulating a static location (Apple or Custom Location) or simulating a user riding a bicycle, running, or driving. The Custom Location option lets you input a static latitude and longitude:
The simulations of a moving device are all in the Cupertino area, so if you need to simulate something else give the multiple
<wpt> tags a shot.
The biggest bug Apple fixed is simulating locations on the device. The location is only simulated while the debugger is running. Stopping the debugger returns control of location services to the appropriate radios and sensors on your iOS Device.