idevice

List Devices

List devices reported by usbmuxd.

List devices from Rust by connecting to usbmuxd and reading the device list:

src/main.rs
use idevice::usbmuxd::{UsbmuxdAddr, UsbmuxdConnection};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // usbmuxd tracks devices connected over USB or network.
    let addr = UsbmuxdAddr::from_env_var()?;
    let mut usbmuxd = UsbmuxdConnection::new(addr.to_socket().await?, 0);

    for device in usbmuxd.get_devices().await? {
        println!("{} ({:?})", device.udid, device.connection_type);
    }

    Ok(())
}

Add the needed features:

Cargo.toml
[dependencies]
idevice = { version = "0.1.64", features = ["usbmuxd"] }
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }

To check the same thing from a terminal, use idevice_id:

Terminal
idevice_id

Listen for attach and detach events:

Terminal
idevice_id -l

The CLI command prints the raw device records returned by usbmuxd. The C++ example shows the same idea with one line per device.

Source

On this page