Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

appium-ios-device

appium1.7mApache-2.02.8.2TypeScript support: included

Appium API for dealing with iOS devices

appium

readme

appium-ios-device

NPM version Downloads

Release

Appium API for dealing with iOS devices. This is mainly a rewrite of libimobiledevice in Node.js. The APIs allow Appium to talk directly to the phone over usbmuxd.

More information can be found at the links below:

Note This module is used and tested by appium-xcuitest-driver, which expects macOS as the host paltform with Xcode. Some features may only work partially on other platforms.

Usage

This module should be used over the utilities and services modules or exported classes in documents due to the complexity of iOS communication. When a new services is implemented, it should be added and made available over the services module.

Methods

  • utilities.getConnectedDevices
  • utilities.getOSVersion
  • utilities.getDeviceTime
  • utilities.getDeviceName
  • utilities.getDeviceInfo
  • utilities.startLockdownSession
  • utilities.connectPort
  • utilities.connectPortSSL
  • utilities.fetchImageFromGithubRepo
  • services.startSyslogService
  • services.startWebInspectorService
  • services.startInstallationProxyService
  • services.startSimulateLocationService
  • services.startAfcService
  • services.startNotificationProxyService
  • services.startHouseArrestService
  • services.startInstrumentService
  • services.startTestmanagerdService
  • services.startMCInstallService
  • services.startImageMounterService

Classes

  • Xctest
    • Allows invoking pre-installed xctest app from iOS devices. No Xcode installation is required. This class simulates the procedure which Xcode uses to invoke xctests.
    • new Xctest(udid, xctestBundleId, targetBundleId, opts)
      • udid - string Device udid.
      • xctestBundleId - string - Bundle Id of xctest app on device. The app must be installed on device.
      • targetBundleId - string - Test target bundle id. null by default.
      • opts - optional addition options to specific XCTestConfiguration and app launch env.
        • conf - properties to override in XCTestConfiguration.
          • productModuleName - string | null
          • targetApplicationArguments - string[] | null
          • testsToRun - string[] | null
          • testsToSkip - string[] | null
        • env - object - key-value pairs to append in xctest app environment
    • xctest.start()
      • Start xctest process. If this method has been called before and the stop() method has not been called, calling this again would return directly.
      • Throws: If xctest bundle id invalid or not installed.
    • xctest.stop()
      • Stop xctest process.

Mount Developer Image

When using a higher version of iOS devices with a lower version of Xcode or other non-macOS operating systems, most of the functions in services or Xctest may not be available because the developer image is not mounted. Sometimes it can be solved automatically by opening Xcode and waiting for a while. But more often you need to manually download and mount the developer image as follows:

  1. Download .dmg file with new Xcode(sometimes beta version is needed) from Apple Developer Downloads Page.
  2. Unarchive new Xcode from .dmg file without replacing old one.
  3. Find the folder named after the target iOS version in (New Xcode.app)/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport. A DeveloperDiskImage.dmg and a DeveloperDiskImage.dmg.signature should be inside that folder.
  4. Copy the folder you found from last step and paste to (Old Xcode.app)/Contents/Developer/Platforms/iPhoneOS.platform/DeviceSupport.
  5. The operations in the above two steps are also applicable to platforms other than the iPhone. e.g. the folder for tvOS is (Xcode.app)/Contents/Developer/Platforms/AppleTVOS.platform/DeviceSupport.
  6. Restart your old Xcode and reconnect your devices, wait for a while until the "preparing device for development" prompt disappears.
  7. You can also mount this image using ideviceimagemounter binary file compiled by libimobiledevice project on your operating system.

These operations are very cumbersome. Fortunately there are many repositories of these developer images in the open source community. The folders mentioned in the above process are zipped and uploaded into open source repositories according to different versions. You can also make your own mirror repository on GitHub in a similar way. With services.startImageMounterService and utilities.fetchImageFromGithubRepo, you can automate the whole process cross-platform.

As an example, assuming we are using a repo from https://github/example/iOSDeviceSupport. All the .zip files are inside DeviceSupportFiles/iOS folder of root. We can check the mount status, download and mount the image using following code:

import { services, utilities } from 'appium-ios-device';
import _ from 'lodash';
const { startImageMounterService } = services;
...
async function checkAndMountDeveloperImage(udid) {
  const imageMountService = await startImageMounterService(udid);
  try {
    const mountStatus = await imageMountService.isDeveloperImageMounted();
    if (!mountStatus) {
      const { fetchImageFromGithubRepo } = utilities;
      const repoOpts = {
        githubRepo: 'example/iOSDeviceSupport',
        subFolderList: ['DeviceSupportFiles', 'iOS']
      }
      const downloadedImagePath = await fetchImageFromGithubRepo(udid, repoOpts);
      if (!_.isEmpty(downloadedImagePath)) {
        const {developerImage, developerImageSignature} = downloadedImagePath;
        await imageMountService.mount(developerImage, developerImageSignature);
      }
    }
  } catch(e) {
    // Failed to mount, do something...
  } finally {
    imageMountService.close();
  }
}

Environment

  • If exists, USBMUXD_SOCKET_ADDRESS is used to get usbmuxd socket address. Mostly useful in cases where the usbmuxd is run by a non-root user.

Test

npm test

changelog

2.8.2 (2025-04-03)

Bug Fixes

2.8.1 (2025-01-05)

Miscellaneous Chores

  • Bump @appium/eslint-config-appium-ts from 0.3.3 to 1.0.1 (#191) (6680e4f)

2.8.0 (2024-12-23)

Features

  • get usbmuxd socket address from USBMUXD_SOCKET_ADDRESS environment (#190) (9a5be45)

2.7.27 (2024-12-06)

Miscellaneous Chores

  • Bump @appium/support from 5.1.8 to 6.0.0 (#189) (6a6d997)

2.7.26 (2024-12-03)

Miscellaneous Chores

2.7.25 (2024-11-11)

Bug Fixes

  • set __ActivateSuspended to not block xctest run by popup (#187) (f45d58d)

2.7.24 (2024-10-28)

Miscellaneous Chores

2.7.23 (2024-08-26)

Bug Fixes

  • Avoid throwing of runtime exception if DTXMessage cannot be decoded (#184) (669c10c)

2.7.22 (2024-07-29)

Miscellaneous Chores

  • Bump @types/node from 20.14.13 to 22.0.0 (#183) (312aa61)

2.7.21 (2024-07-09)

Miscellaneous Chores

2.7.20 (2024-06-19)

Miscellaneous Chores

2.7.19 (2024-06-19)

Miscellaneous Chores

2.7.18 (2024-06-12)

Miscellaneous Chores

  • Bump @appium/support from 4.5.0 to 5.0.3 (#181) (560fcdf)

2.7.17 (2024-06-04)

Miscellaneous Chores

  • Bump semantic-release from 23.1.1 to 24.0.0 and conventional-changelog-conventionalcommits to 8.0.0 (#178) (4e2763b)

2.7.16 (2024-05-16)

Miscellaneous Chores

  • Update dev dependencies (e237d49)

2.7.15 (2024-04-09)

Miscellaneous Chores

2.7.14 (2024-04-09)

Miscellaneous Chores

  • Bump @typescript-eslint/parser from 6.21.0 to 7.6.0 (#174) (66a4713)

2.7.13 (2024-03-07)

Miscellaneous Chores

2.7.12 (2024-03-02)

Miscellaneous Chores

2.7.11 (2024-01-17)

Miscellaneous Chores

  • Bump semantic-release from 22.0.12 to 23.0.0 (#159) (9bc56e5)
  • use latest lts for the publishment (#160) (35f989d)

2.7.10 (2023-11-17)

Miscellaneous Chores

  • Bump semantic-release from 21.1.2 to 22.0.8 (#154) (affbaab)

2.7.9 (2023-11-06)

Miscellaneous Chores

  • Bump @types/sinon from 10.0.20 to 17.0.0 (#152) (224242f)

2.7.8 (2023-11-01)

Miscellaneous Chores

2.7.7 (2023-10-26)

Miscellaneous Chores

  • Bump @typescript-eslint/eslint-plugin from 5.62.0 to 6.9.0 (#149) (8fa3671)

2.7.6 (2023-10-20)

Miscellaneous Chores

  • Bump eslint-config-prettier from 8.10.0 to 9.0.0 (#146) (326793c)

2.7.5 (2023-10-19)

Miscellaneous Chores

  • Use latest teen_process types (70586ef)

2.7.4 (2023-10-19)

Miscellaneous Chores

2.7.3 (2023-09-17)

Miscellaneous Chores

  • Bump @types/teen_process from 2.0.0 to 2.0.1 (#134) (183f168)

2.7.2 (2023-08-28)

Miscellaneous Chores

  • Bump conventional-changelog-conventionalcommits (#130) (9625967)

2.7.1 (2023-08-25)

Miscellaneous Chores

  • Bump semantic-release from 20.1.3 to 21.1.0 (#127) (7d0faa4)

2.7.0 (2023-08-25)

Features

2.6.1 (2023-08-14)

Miscellaneous Chores

  • Bump lint-staged from 13.3.0 to 14.0.0 (#125) (ed1b7ac)

2.6.0 (2023-08-03)

Features

  • Add ImageMounterService and auto fetch developer image if start service failed with 'InvalidService' (#112) (9fcc5c3)

2.5.4 (2023-07-07)

Miscellaneous Chores

2.5.3 (2023-06-07)

Miscellaneous Chores

  • Bump conventional-changelog-conventionalcommits (#117) (a01dfbe)

2.5.2 (2023-05-18)

Miscellaneous Chores

  • Bump @appium/support from 3.1.11 to 4.0.0 (#115) (8035128)

2.5.1 (2023-05-12)

Bug Fixes

  • Prevent possible memory leak on logs collection (#114) (a942cd7)

2.5.0 (2023-04-14)

Features

  • add xctest class which can be used to start WDA (#110) (f3740fd)

2.4.12 (2023-04-07)

Bug Fixes

  • The issue which auxBuffer cannot be correctly handled as parameter. (#108) (727cc8c)

2.4.11 (2023-02-28)

Miscellaneous Chores

  • Workaround TypeError on rpc messages transformation (#105) (e7b9c82)

2.4.10 (2023-02-28)

Miscellaneous Chores

2.4.9 (2023-01-17)

Miscellaneous Chores

  • Bump semantic-release from 19.0.5 to 20.0.2 (#103) (c21dd35)

2.4.8 (2022-12-14)

Miscellaneous Chores

  • Bump @appium/support from 2.61.1 to 3.0.0 (#102) (66983e9)

2.4.7 (2022-12-01)

Miscellaneous Chores

2.4.6 (2022-11-06)