Monthly Archives: February 2017

Custom location and movement on Xamarin Remoted iOS Simulator for Windows

When I was building a Xamarin PoC at the client, I was disappointed to notice that there wasn’t any way of simulating the user’s location on the Remoted iOS Simulator for Windows. Not to mention simulating a walk or bike ride around an area other then the standard rides around Apple’s headquarters.

Setting a custom location

I did notice that setting a custom location was possible on the iOS simulator on OSX.
Enter Custom Location on Mac
Unfortunately, this does not exist on the remoted simulator. However, soon I discovered that when I’d open up the same simulator on iOS and Windows, changing the location on my Mac would also change the position on my Remoted Simulator on Windows.
In order to do this, you need to start a particular iOS simulator on Windows, let’s say iPhone 6 – iOS 10.2. Once it is booted up, go to your Mac, cmd+space and type “Simulator”. Then in the Menu bar go to ‘Hardware’, ‘Device’ and select the same simulator as the one that is running on your Windows machine. If everything goes well, you should get an error message saying something like the device is already booted.
Unable to boot device errr message
Close the error message and in your Menu bar go to ‘Debug’, ‘Location’ and select ‘Custom Location…’. Enter any coordinates in the window, click ‘OK’ and you should see the position on your simulator on Windows update as well. The easiest way to check this is by opening the Maps app in your simulator on Windows, or in your own app ofcourse :-).

Now, take another step and move forward…

That already helped me a lot! Now I didn’t need to mock all my data around Cupertino anymore.
But what if I want to simulate a walk or bike ride around Brussels for example, instead of being at one fixed location? Simple! Just do whatever I just described and change your location every 2 seconds… 🙂 This idea may sound stupid, but it is exactly what I’m going to do! So, as a complete OSX n00b, I looked into things like automation tools and stuff and so I stumbled upon AppleScript. Yes, that sounds as scary as it is! With this AppleScript, you can basically script everything on you Mac, in a programming language that you might call awkward at least… Especially for a ‘true’ developer.
I played around with it for a bit and in no time, after some trail and error, I was able to open up the ‘Enter Location ‘ popup window and programmatically set a Longitude and Latitude. You can run this script in the Script Editor tool on your Mac if you want, but make sure the Simulator is already running!

The only thing left to do, is repeat this process and update the Longitude and Latitude each time. I found out that reading XML files with AppleScript is quite simple, so I went to https://gpxgenerator.com/. On this website, you can put waypoints on a map and generate a GPX file, which is just a simple XML file representing the route you outlined. Although, in the generated GPX file there is an indication about how long it take to get from one waypoint to the next, I’m going to ignore this for now and simply say in my script that there is a certain fixed amount of time between each waypoint.

Now I only have to read this XML file, loop over the elements and read the Longitude and Latitude of each one, enter these values in my ‘Enter Location’ popup window, wait a couple of seconds and continue my loop. Simple right? And this is what my final script looks likes. It takes 2 command line parameters: the location of the GPX file and the timeout between each iteration.

You can now easily call this script as follows in the terminal on your Mac: osascript [path to you script] [path to your gpx xml file] [time to sleep between each iteration]

Launch script from terminal

Simulator in action:
 Location updated op Remoted iOS Simulator
Done! Simple but effective imho! 🙂
I’m putting this code on GitHub, so if you have any other ideas on how to improve the script or its functionality, just do a PR!
Have fun!