iosios-simulator

Is there a way to programmatically toggle 'freeway drive' on the ios simulator


I know theres the xcrun simctl command. but that only can help me launch the simulator and my app. how do I tell the simulator to toggle freeway drive from the command line/script?


Solution

  • If you run xcrun simctl, it will show you a list of commands. One of them is location. You can see a list of location commands with xcrun simctl location:

    $ xcrun simctl location
    Control a device's simulated location
    Usage: simctl location <device> <action> [arguments]
    
        list
            List available simulation scenarios.
    
        clear
            Stop any running scenario and clear any simulated location.
    
        set <lat1>,<lon1>
            Set the location to a specific latitude and longitude.
    
        run <scenario>
            Run a simulated location scenario (use the list action to get a list of scenarios).
    
        start [--speed=<meters/sec>] [--distance=<meters per second>|--interval=<seconds>] <lat1>,<lon1> <latN>,<lonN>...
            Set the location to a series of waypoints specified as 'lat,lon' pairs, interpolating between them over time.
            At least two waypoints are required. Use '-' to read waypoints from stdin, one waypoint per line.
    
            Speed specifies how quickly to move between waypoints in meters per second. If not specified 20m/s is used.
    
            The system will issue location updates along the path between each pair of waypoints. Use distance or interval to
            control how often those updates are issued. Distance will issue an update every <meters> travelled without regard
            for the time between updates. Interval will issue updates at fixed times without regard for how much
            the location moves between updates.
            If neither are specified an interval of 1.0 seconds is used. If both are specified the system picks ones.
    
            Example simulating a direct line between San Francisco and New York City, with updates every km:
              start --distance=1000 --speed=260 37.629538,-122.395733 40.628083,-73.768254
    
    Latitude and longitude pairs must be specified using '.' as the decimal separator and ',' as the field separator.
    

    E.g., you can start a freeway drive with (obviously, replacing “…” with your device):

    xcrun simctl location … run "Freeway Drive"
    

    FWIW, when I do this, I do not see the selection in the Simulator’s “Location” menu option change to reflect this, but if you launch an app that shows your location (e.g., the Maps app), you will see that the location actually is updating.