VPhoneLocationProvider Throttling Behavior in vphone-cli: Live vs Replay Modes

VPhoneLocationProvider forwards live macOS CoreLocation updates to the guest iOS VM instantly without throttling, while enforcing configurable interval delays only during location replay simulations.

The VPhoneLocationProvider class in the Lakr233/vphone-cli repository manages location services for iOS virtualization, bridging host macOS location data to a guest VM. Understanding its throttling behavior is essential for developers building location-aware testing workflows, as the implementation distinguishes sharply between real-time forwarding and synthetic replay modes.

Live Location Forwarding Without Throttling

When operating in live forwarding mode, VPhoneLocationProvider does not implement any artificial delay or rate limiting. It registers as a CoreLocation delegate and immediately transmits each incoming location update to the guest system via vsock.

According to the source code in sources/vphone-cli/VPhoneLocationProvider.swift, the provider invokes control.sendLocation(...) directly within the location callback handler (lines 88‑95). This synchronous dispatch ensures that GPS updates reach the iOS VM as soon as macOS reports them, preserving the native update frequency determined by the host's GPS hardware and CoreLocation configuration.

let locationProvider = VPhoneLocationProvider(control: vphoneControl)
locationProvider.startForwarding()   // Starts CoreLocation updates
// Each location callback is instantly relayed to the guest.

Replay Mode Throttling and Interval Control

Throttling is explicitly enforced only when using the replay functionality. The startReplay(name:points:intervalSeconds:loop:) method simulates a GPS route by injecting waypoints with a mandatory pause between each point.

The implementation clamps the intervalSeconds parameter to a minimum of 0.1 seconds to prevent excessive CPU usage or network flooding. At lines 25‑27 of VPhoneLocationProvider.swift, the code calculates the sleep duration:

let sleepNanos = UInt64((max(intervalSeconds, 0.1) * 1_000_000_000).rounded())

The replay loop (lines 58‑61) suspends the task using Task.sleep(nanoseconds:) between location injections:

try? await Task.sleep(nanoseconds: sleepNanos)

This design allows developers to specify custom replay speeds—defaulting to 1.5 seconds per point—while ensuring the system cannot be configured to zero-delay flooding.

Configuring Replay Intervals

To replay a predefined route with a specific throttling interval, instantiate the provider and invoke startReplay with your desired timing parameters:

let points = [
    VPhoneLocationProvider.ReplayPoint(latitude: 37.7749, longitude: -122.4194),
    VPhoneLocationProvider.ReplayPoint(latitude: 34.0522, longitude: -118.2437)
]

// Replay the points every 0.5 seconds, looping forever
locationProvider.startReplay(
    name: "US-West-Tour",
    points: points,
    intervalSeconds: 0.5,
    loop: true
)

To terminate an active replay session and stop location injection, call the stopReplay() method.

Source File Architecture

The location provider functionality spans three primary files in the sources/vphone-cli/ directory:

  • VPhoneLocationProvider.swift – Contains the core VPhoneLocationProvider class, implementing live forwarding, replay logic, and throttling interval calculations.
  • VPhoneControl.swift – Manages the vsock communication channel used by the provider to transmit sendLocation payloads to the guest VM.
  • VPhoneMenuLocation.swift – Provides the interactive menu interface for toggling location services and selecting replay presets.

Summary

  • Live mode forwards CoreLocation updates immediately without throttling via control.sendLocation(...).
  • Replay mode enforces a configurable minimum interval of 0.1 seconds between simulated location points.
  • The startReplay(name:points:intervalSeconds:loop:) method defaults to 1.5 seconds but accepts custom values clamped to the 0.1s floor.
  • Replay timing uses Task.sleep(nanoseconds:) for asynchronous suspension between waypoints.

Frequently Asked Questions

Does VPhoneLocationProvider throttle live GPS updates from the host Mac?

No. When live forwarding is active, the provider transmits every CoreLocation update to the guest VM instantly. No artificial delays or rate limiting are applied to real-time host location data as received from CoreLocation.

What is the minimum interval I can set for location replay?

The implementation enforces a hard floor of 0.1 seconds (100 milliseconds). Any intervalSeconds value below 0.1 is clamped to this minimum in the nanosecond calculation at line 25 of VPhoneLocationProvider.swift.

How do I stop a running location replay?

Invoke the stopReplay() method on your VPhoneLocationProvider instance. This cancels the underlying asynchronous task, immediately halting the injection of replay points regardless of whether the loop parameter was set to true.

Which file handles the actual transmission of location data to the iOS VM?

The sendLocation calls are defined in VPhoneLocationProvider.swift, but the class delegates to VPhoneControl.swift for the actual vsock communication. This separation of concerns keeps transport logic isolated from location simulation logic.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →