idb (iOS Development Bridge)
repository·main·Indexed 26 days ago
https://github.com/facebook/idbA command line interface for automating iOS Simulators and Devices. idb uses a remote architecture consisting of a macOS-based companion and a Python-based client to provide scalable automation and access to private iOS frameworks. It leverages underlying frameworks including FBDeviceControl for device control, FBSimulatorControl for simulator management, and FBControlCore for core commands such as application lifecycle management, file operations, and crash log retrieval.
What's inside idb
- iOS Development Bridge (idb) is a versatile tool designed for automating iOS Simulators and Devices. It provides a consistent and human-friendly interface to expose functionality that is otherwise spread across various Apple developer tools.
Overview of idb-repl
mainidb-replis an interactive REPL (Read-Eval-Print-Loop) that allows you to run Swift code inside a live process on an iOS Simulator. You can type or pipe Swift code, which is then compiled, injected into a running process, executed, and the results are streamed back to your terminal. It is particularly useful for inspecting runtime environments, exploring app state, running code within test bundles, or automating complex sequences of steps.Overview of FBDeviceControl
mainFBDeviceControlis a framework designed for controlling iOS Devices. It is a sister-framework toFBSimulatorControl(which is used for iOS Simulators).While you can use
FBDeviceControlas a standalone framework, it is recommended to useidb, which utilizesFBDeviceControlunder the hood and provides more sensible default configurations for many common use cases.Understand FBSimulatorControl
mainFBSimulatorControlis a standalone macOS Framework that implements all functionality associated with iOS Simulators withinidb. It can be used independently of theidbproject.Understand idb Framework Architecture
mainThe
idbecosystem is built upon several core frameworks that can be used independently of theidbCLI.FBControlCore: Defines common interfaces and provides shared functionality for both Device and Simulator frameworks.FBSimulatorControl: Implements functionality specific to iOS Simulators.FBDeviceControl: Implements functionality specific to physical iOS Devices.
These frameworks use an abstraction layer where
FBiOSTarget(a protocol) represents either a simulator or a device, allowing higher-level tools to treat them uniformly.Understand the idb architecture components
mainThe
idbsystem consists of two primary components that must both be present to execute commands:idbcli: A Python 3-based command-line interface that serves as a thin wrapper for theidb_companion. It communicates with the companion viagRPC(using either TCP or Unix Domain Sockets). Because it is Python-based, the CLI does not need to run on the same Mac that is physically attached to the iOS device or simulator.idb_companion: AgRPCserver that must run on macOS. It interfaces with native APIs to automate Simulators and Devices by linking theFBSimulatorControlandFBDeviceControlframeworks. Eachidb_companioninstance acts as a server for a single iOS target (one specific device or simulator).
Understand the idb-repl architecture
mainThe
idb-replworkflow consists of three main components that orchestrate code execution on a simulator:idb-repl(the driver): The CLI tool you interact with. It compiles your Swift code and orchestrates the session. It communicates with the companion via gRPC but does not talk to the target process directly.idb_companion(the server): A macOS process that manages simulators and exposes a gRPC API. It is responsible for injecting and running your code inside the target process.- The target process: The actual environment where your code executes, which can be an app, the simulator itself, or a test bundle.
Data Flow:
you──▶idb-repl(driver) ──(gRPC)──▶idb_companion(server) ──▶target process on the simulator(app / simulator / test bundle)Understand idb_companion and gRPC Service
mainThe
idb_companionacts as a gRPC server that exposes the functionality of theFBSimulatorControlandFBDeviceControlframeworks.Key components:
main: The entrypoint for the companion. It handles gRPC server startup flags and exposes destructive "CRUD" commands for managing Simulators and Devices. Note that destructive commands are intentionally excluded from the gRPC interface and must be run on the host.FBIDBServiceHandler: A C++ class implementing the gRPC interface. It forwards requests to a thread pool and manages the conversion of gRPC calls to underlying framework calls (often involvingFBFuture).FBIDBCommandExecutor: An Objective-C facade that provides a simplified interface over the underlying frameworks, shielding the C++ service handler from complex framework implementation details.
Understand FBDeviceControl and MobileDevice.framework
mainFBDeviceControlis a standalone macOS Framework that implements iOS device functionality foridb. It is built upon Apple's privateMobileDevice.framework(typically located at/System/Library/PrivateFrameworks/MobileDevice.framework/MobileDevice).Key integration details:
- API Style: Most
MobileDevice.frameworkAPIs are CoreFoundation-style (C symbols withCFobjects).FBDeviceControlwraps these into Objective-C classes likeFBAMDevice. - Xcode Dependency: Some device operations require Xcode to be installed and selected via
xcode-select.FBDeviceControldefers loading Xcode-specific functionality to avoid failures when Xcode is not required (e.g., basic device listing works without Xcode). - Canonical Source:
FBDeviceControluses these APIs as the canonical way to interact with iOS devices on macOS, similar to how Finder, iTunes, and Xcode operate.
- API Style: Most
Use XCTestBootstrap to execute XCTest bundles
mainXCTestBootstrap is a macOS library designed for executing XCTest bundles. While it can be used directly as a Framework, it is part of the broaderidbproject. For most use cases, it is recommended to useidbinstead, as it provides more sensible default configurations for test execution.Use Custom Device Sets for Isolation
mainWhile the "Default Device Set" is located at
~/Library/Developer/CoreSimulator/Devicesand used byXcode.app, you can place custom device sets at any location on disk. This is useful for:- Isolating filesystems of different iOS Simulators.
- Preventing data races when multiple independent processes manage iOS Simulators on the same host.
Use interactive mode in idb-repl
mainInteractive mode is experimental and incomplete. For reliable, scriptable use, prefer one-shot mode by passing Swift code as a trailing argument.
In an interactive session (running a subcommand without a trailing code argument), lines that do not start with
/are treated as Swift code. To execute the collected code, use the/runcommand. The collected code must end in areturnstatement to surface a value.Interactive Commands:
Command Description /runCompile and execute the collected code. The collected lines then reset for the next block. /helpShow available commands. /exitKill subprocesses and exit. Always send this last when piping input.