Set the location in iPhone Simulator
As of iOS 5, the simulator has a configurable location.
Under the Debug menu, the last entry is "Location"; this gives you a sub menu with:
- None
- Custom Location
- Apple Stores
- Apple
- City Bicycle Ride
- City Run
- Freeway Drive
Custom Location lets you enter a Lat/Long value. Bicycle ride, City Run, and Freeway Drive are simulation of a moving location (in Cupertino, of course).
Of course, this does nothing to help with debugging for iOS 4 (or earlier); but it's a definite improvement!
- Run project in iPhone Simulator
-
Create in TextEdit file following file, call it MyOffice for example. Make extension as .gpx
<?xml version="1.0"?> <gpx version="1.0" creator="MyName"> <wpt lat="53.936166" lon="27.565370"> <name>MyOffice</name> </wpt> </gpx>
Select in Xcode at the Simulate area
Add GPX File to Project...
- Add created file from menu to project.
- Now you can see your location in Simulate area:
XCode 11.3 and prior:
Debug -> Location -> Custom Location
XCode 11.4+:
Features -> Location -> Custom Location
To find out which XCode version you have
$ /usr/bin/xcodebuild -version
in iOS Simulator menu, go to Debug -> Location -> Custom Location. There you can set the latitude and longitude and test the app accordingly. This works with mapkit and also with CLLocationManager.
In my delegate callback, I check to see if I'm running in a simulator (#if TARGET_ IPHONE_SIMULATOR
) and if so, I supply my own, pre-looked-up, Lat/Long. To my knowledge, there's no other way.