Monday, January 5, 2015

Simulating iOS Background Location Changes from the Comfort of Your Desk

Xcode offers a handy feature for developers that are working with location services. Simulating a Location at Runtime allows the developer to specify a location that the device will report to apps as they run. You can even use prerecorded GPX files to simulate walking, running, biking or driving along a route to see how the location changes are handled by your app.

However, simulating location changes in apps that have been terminated is a bit trickier, as the debug area option to simulate location is only available when you're debugging a process. To work around this, you can follow these steps:

  1. Run the app in which you want to simulate a background location change.
  2. Stop the app.
  3. Create a dummy project - I just use the single view application template.
  4. Run the dummy project on the same device.
  5. In the debug bar for the dummy project, choose a location, or add a GPX file containing the location changes you want to simulate to your project and choose it.




Even though the app that you're wanting to simulate a background location change was stopped at step 2, you should see it get a location services update via application:didFinishLaunchingWithOptions:, with the UIApplicationLaunchOptionsLocationKey set in the options dictionary. And, you can do this from the comfort of your desk without needing to take your iPhone to the location you're wanting to test in.