I've just updated to XCode 4.2 and I see a cool feature that allows me to manually set the device location. Does anyone know of a way to accomplish the same thing programmatically? I'd like to set the location in some unit tests.
Starting with Xcode 4.2, there is now a way under the Debug menu on the simulator using the Location entry that allows setting a custom location or selecting from some predefined rides and locations. in iOS Simulator menu, go to Debug -> Location -> Custom Location.
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. Share Improve this answer
Changing Location of simulator does not affect already built, loaded apps. For example, if you have an app with Google map view running on simulator the map won't be updated till you rebuild the app. Also, keep in mind that when entering custom lat and long you should be careful with longitudes with (-) sign and without.
For iOS simulator, it is now located under "Features" – J. Saw Jun 8 '20 at 16:53 Add a comment | 89 Run project in iPhone Simulator Create in TextEdit file following file, call it MyOffice for example.
The following AppleScript will let you set the location of the iOS Simulator. It should be possible to integrate this kind of script into a unit test script, or have your script generate the equivalent AppleEvents.
tell application "iOS Simulator"
activate
end tell
tell application "System Events"
tell process "iOS Simulator"
tell menu bar 1
tell menu bar item "Debug"
tell menu "Debug"
tell menu item "Location"
click
tell menu "Location"
click menu item "Custom Location…"
end tell
end tell
end tell
end tell
end tell
tell window 1
set value of text field 1 to "40.69"
set value of text field 2 to "-74.045"
click button "OK"
end tell
end tell
end tell
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With