Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulating location updates on the iPhone Simulator

Tags:

I want to allow users to set the GPS information on the iPhone Simulator via GUI.

But I'm not sure how to archieve this - it seems that this tool called iSimulate does this somehow by installing an own SDK. But I can't figure out how they "override" / "hack" the simulator by that.

Thanks!

like image 502
stephanos Avatar asked Jan 13 '10 11:01

stephanos


People also ask

How do you mock locations in simulation?

settings> system > developer optionsFind the option select mock location app Then select the app you downloaded from step 1.

How do you change location on iPhone Simulator?

in iOS Simulator menu, go to Debug -> Location -> Custom Location. There you can set the latitude and longitude and test the app accordingly.

How do you simulate a location?

Click the location on the map you want to simulate, and then press the lowercase L key. A dialog will appear with the message, “Simulated Location Set”. After a short time, the simulated location you set in the Editor will appear as a pink dot in the Android Emulator. Click anywhere on the map, and press Shift+L.


2 Answers

Added a second answer since there are now integrated features in Xcode (≥4.2). There are two ways to simulate location updates:

  • In the iOS Simulator, under "Debug/Location" you're able to specify a constant latitude/longitude or select several predefined profiles like "City Run" or "Freeway Drive".
  • In Xcode there's a new location icon in the debugger, right next to the Step Out button. It lets you select several hardcoded cities worldwide and add a custom GPX file to your project. The nice thing about location simulation in Xcode is that it also works on the device (just don't forget to turn it off again otherwise your auto timezone will be wrong!). The custom GPX file is nice, too, although it sometimes crashes Xcode if the GPX file is not recognized. Make sure you use <wpt> tags only:
<?xml version="1.0"?> <gpx version="1.1" creator="Xcode">    <wpt lat="47.52789018096815" lon="7.385249894876031"></wpt>   <wpt lat="47.52720984945248" lon="7.382647784661411"></wpt>   ... </gpx> 
like image 97
Ortwin Gentz Avatar answered Oct 06 '22 00:10

Ortwin Gentz


As far as I know, iSimulate is not employing any hacks. It is code that runs within your app on the Simulator which communicates with a device over the network. When it receives messages from the device (touches, GPS, acceleration) it simulates those events by calling your app's code as though the system had triggered them.

For example, to receive GPS location updates you must create an instance of CLLocationManager and then configure one of your classes to be its delegate. Well, on the iPhone Simulator you can instead start code that sends fake messages to your delegate instead. If you just call a delegate's method like this:

[delegate locationManager:nil didUpdateToLocation:newLocation fromLocation:oldLocation]; 

Your code won't have to know that the location update is fake. If you want to get fancy, you could create a new class that implements all the public methods of CLLocationManager but which sends fake messages instead. (Since Objective-C is dynamically typed, it won't need to be a subclass, as long as it responds to all the messages you send.)

As a side note, you can use these compiler macros to keep code simulator-only:

#if TARGET_IPHONE_SIMULATOR    locationManager = (id)[[MyFakeLocationManager alloc] init]; #else    locationManager = [[CLLocationManager alloc] init]; #endif 
like image 25
benzado Avatar answered Oct 06 '22 00:10

benzado