Appium iOS Device API
appium-ios-device is a robust Node.js library providing a comprehensive API for advanced, low-level programmatic interaction with iOS devices. It acts as a direct, pure JavaScript/TypeScript rewrite of the `libimobiledevice` C library, enabling Appium and other tools to communicate with iPhones, iPads, and iPods over `usbmuxd` without relying on macOS-specific tools like Xcode for basic operations. This package facilitates a wide array of functionalities, including retrieving detailed device information (OS version, name, device time), establishing secure port connections, and managing various iOS services such as syslog monitoring, web inspector sessions, app installation proxying, and location simulation. A key differentiator is its `Xctest` class, which allows invoking pre-installed XCUITest applications on devices without needing a full Xcode environment on the host machine. Currently at version 3.1.11, the library undergoes active development with frequent patch and minor releases, reflecting ongoing maintenance and adaptation to new iOS versions and underlying dependencies. While primarily used and tested within the `appium-xcuitest-driver` on macOS, it offers partial functionality on other platforms, though full capabilities often necessitate specific developer image mounts or a macOS host with Xcode.
Common errors
-
Error: The current Node.js version (vX.Y.Z) is not supported. Please upgrade Node.js.
cause Attempting to use the package with an incompatible Node.js version as specified in its `engines` field.fixUpdate your Node.js environment to version 20.19.0+, 22.12.0+, or 24.0.0+ using a tool like `nvm` (`nvm install 20 && nvm use 20`). -
No iOS devices found connected via USB.
cause No physical iOS devices are connected, or the connected device is not recognized by `usbmuxd` (e.g., not trusted, locked, or usbmuxd service not running).fixEnsure the iOS device is connected via USB, unlocked, has 'trusted' the computer, and verify `usbmuxd` is running on your host system. -
Mismatched Xcode/iOS version or missing developer image.
cause Attempting to use a service or feature (like XCUITest) that requires a developer image to be mounted on the device, but it's missing or incompatible.fixEnsure your Xcode version is compatible with the connected iOS device's OS. If not, manually download and mount the correct `DeveloperDiskImage.dmg` and `DeveloperDiskImage.dmg.signature` files.
Warnings
- breaking This package strictly requires Node.js versions ^20.19.0, ^22.12.0, or >=24.0.0. Older Node.js versions are not supported and will lead to installation or runtime failures.
- gotcha The module is primarily developed and tested on macOS with Xcode installed. While some features may work on other platforms, full functionality and stability are best achieved on a macOS host.
- gotcha Advanced services (e.g., `services.startSyslogService`, `Xctest` class) may require a mounted developer image on the iOS device, especially when using a higher iOS version with an older Xcode, or on non-macOS hosts.
Install
-
npm install appium-ios-device -
yarn add appium-ios-device -
pnpm add appium-ios-device
Imports
- utilities
const utilities = require('appium-ios-device').utilities;import { utilities } from 'appium-ios-device'; - services
const services = require('appium-ios-device').services;import { services } from 'appium-ios-device'; - Xctest
const { Xctest } = require('appium-ios-device');import { Xctest } from 'appium-ios-device';
Quickstart
import { utilities } from 'appium-ios-device';
async function getAndDisplayConnectedDevices() {
console.log('Attempting to discover connected iOS devices...');
try {
const devices = await utilities.getConnectedDevices();
if (devices.length === 0) {
console.log('No iOS devices found connected via USB.');
console.log('Please ensure your device is connected, unlocked, and trusted the computer.');
return;
}
console.log(`Successfully found ${devices.length} iOS device(s):`);
for (const udid of devices) {
console.log(`\n Device UDID: ${udid}`);
const deviceInfo = await utilities.getDeviceInfo(udid);
console.log(` Name: ${deviceInfo.deviceName}`);
console.log(` iOS Version: ${deviceInfo.productVersion}`);
console.log(` Product Type: ${deviceInfo.productType}`);
console.log(` Build Version: ${deviceInfo.buildVersion}`);
// More properties are available in deviceInfo object
// e.g., deviceInfo.modelNumber, deviceInfo.serialNumber
}
console.log('\nDiscovery complete.');
} catch (error) {
console.error('Failed to communicate with iOS devices. Ensure usbmuxd is running and devices are connected.', error);
console.error('Common issues: Older Node.js version, unmounted developer image (for advanced services).');
}
}
getAndDisplayConnectedDevices();