Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically setting iphone simulator location

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.

like image 471
JonnyBoy Avatar asked Nov 04 '11 20:11

JonnyBoy


People also ask

How to set a custom location in iOS simulator?

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.

How to set latitude and longitude in iOS simulator?

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

What happens if I change the location of the simulator?

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.

Where is the MYOffice project in iOS simulator?

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.


1 Answers

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
like image 152
Mike Akers Avatar answered Oct 19 '22 23:10

Mike Akers