Skip to content

Commit 8d6a1bb

Browse files
hannojgV3RON
andauthored
feat: Allow iOS device lookup by UUID (#113)
## Description <!-- Provide a general summary of your changes --> Allows looking up a physical iOS device not just by name, but also uuid. ## Related Issue <!--- This project only accepts pull requests related to open issues --> <!--- If suggesting a new feature or change, please discuss it in an issue first --> <!--- If fixing a bug, there should be an issue describing it with steps to reproduce --> <!--- Please link to the issue here: --> / ## Context <!-- Why this feature was implemented in this particular way? --> <!-- Is there anything reviewer needs to know before conducting code review? --> When running test on AWS DF we just get the UUID in the envs. Right now i have to do a manual lookup to get the device name which is a bit cumbersome, and it would be nicer to just pass the uuid :) ## Testing <!-- Please describe how you tested your changes --> added a test to the repo --------- Co-authored-by: Szymon Chmal <szymon@chmal.it>
1 parent dda0db0 commit 8d6a1bb

5 files changed

Lines changed: 59 additions & 8 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
__default__: patch
3+
---
4+
5+
Harness now lets you target connected physical iOS devices by hardware UDID as well as by device name or CoreDevice identifier, which makes it easier to select the exact device when multiple phones share similar names.

packages/platform-ios/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,15 @@ Creates an iOS simulator device configuration.
6868
- `deviceName` - Name of the iOS simulator (e.g., 'iPhone 16 Pro Max')
6969
- `osVersion` - iOS version (e.g., '18.0')
7070

71-
### `applePhysicalDevice(deviceName)`
71+
### `applePhysicalDevice(deviceNameOrId)`
7272

7373
Creates a physical Apple device configuration.
7474

7575
**Parameters:**
7676

77-
- `deviceName` - Name of the physical device (e.g., 'iPhone (Your Name)')
77+
- `deviceNameOrId` - Name, CoreDevice identifier, or hardware UDID of the
78+
physical device (e.g., 'iPhone (Your Name)' or
79+
'6954F636-D116-52FA-9D00-8298BBB63705')
7880

7981
## Requirements
8082

packages/platform-ios/src/__tests__/launch-options.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, expect, it } from 'vitest';
22
import {
33
getDeviceConnectionHost,
44
getDeviceCtlLaunchArgs,
5+
isMatchingDevice,
56
} from '../xcrun/devicectl.js';
67
import { getSimctlChildEnvironment } from '../xcrun/simctl.js';
78

@@ -62,4 +63,31 @@ describe('Apple app launch options', () => {
6263
})
6364
).toBe('fd12:3456:789a::1');
6465
});
66+
67+
it('matches physical devices by name, CoreDevice identifier, or hardware UDID', () => {
68+
const device = {
69+
identifier: '6954F636-D116-52FA-9D00-8298BBB63705',
70+
deviceProperties: {
71+
name: 'G22RJQXC3V',
72+
osVersionNumber: '26.0',
73+
},
74+
hardwareProperties: {
75+
marketingName: 'iPhone',
76+
productType: 'iPhone17,1',
77+
udid: '00008140-001600222422201C',
78+
},
79+
};
80+
const matchesName = isMatchingDevice(device, 'G22RJQXC3V');
81+
const matchesIdentifier = isMatchingDevice(
82+
device,
83+
'6954F636-D116-52FA-9D00-8298BBB63705'
84+
);
85+
const matchesUdid = isMatchingDevice(device, '00008140-001600222422201C');
86+
const matchesUnknownName = isMatchingDevice(device, 'Unknown iPhone');
87+
88+
expect(matchesName).toBe(true);
89+
expect(matchesIdentifier).toBe(true);
90+
expect(matchesUdid).toBe(true);
91+
expect(matchesUnknownName).toBe(false);
92+
});
6593
});

packages/platform-ios/src/xcrun/devicectl.ts

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,32 @@ export const stopApp = async (
331331
]);
332332
};
333333

334+
export const isMatchingDevice = (
335+
device: AppleDeviceInfo,
336+
identifier: string
337+
): boolean => {
338+
return (
339+
device.deviceProperties.name === identifier ||
340+
device.identifier === identifier ||
341+
device.hardwareProperties.udid === identifier
342+
);
343+
};
344+
334345
export const getDevice = async (
335-
name: string
346+
identifier: string
336347
): Promise<AppleDeviceInfo | null> => {
337348
const devices = await listDevices();
338-
return (
339-
devices.find((device) => device.deviceProperties.name === name) ?? null
340-
);
349+
const matchingDevice = devices.find((device) => {
350+
return isMatchingDevice(device, identifier);
351+
});
352+
353+
return matchingDevice ?? null;
341354
};
342355

343-
export const getDeviceId = async (name: string): Promise<string | null> => {
344-
const device = await getDevice(name);
356+
export const getDeviceId = async (
357+
identifier: string
358+
): Promise<string | null> => {
359+
const device = await getDevice(identifier);
345360
return device?.identifier ?? null;
346361
};
347362

website/src/docs/platforms/ios.mdx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Xcode often installs multiple runtime versions (e.g., iOS 17.0 and iOS 18.0). Si
6161
### Physical Devices
6262

6363
To run on a connected physical iOS device, use the `applePhysicalDevice()` helper.
64+
You can identify the device by name, CoreDevice identifier, or hardware UDID.
6465

6566
```javascript
6667
applePlatform({

0 commit comments

Comments
 (0)