@@ -4,6 +4,44 @@ import path from 'node:path';
44import { sleep } from './actions' ;
55import { getAppId , getAppPath } from './constants' ;
66
7+ function getIosSimulatorUdidForSimctl ( ) : string {
8+ try {
9+ let udid =
10+ ( driver . capabilities as Record < string , unknown > ) [ 'appium:udid' ] ?. toString ( ) ??
11+ ( driver . capabilities as Record < string , unknown > ) . udid ?. toString ( ) ??
12+ ( driver . capabilities as Record < string , unknown > ) . deviceUDID ?. toString ( ) ??
13+ process . env . SIMULATOR_UDID ??
14+ '' ;
15+ if ( udid && udid !== 'auto' ) return udid ;
16+ } catch {
17+ /* ignore */
18+ }
19+ try {
20+ const line = execSync ( 'xcrun simctl list devices booted' , { encoding : 'utf8' } ) ;
21+ const match = line . match ( / \( ( [ 0 - 9 A - F ] { 8 } - [ 0 - 9 A - F ] { 4 } - [ 0 - 9 A - F ] { 4 } - [ 0 - 9 A - F ] { 4 } - [ 0 - 9 A - F ] { 12 } ) \) / i) ;
22+ if ( match ) return match [ 1 ] ?? '' ;
23+ } catch {
24+ /* ignore */
25+ }
26+ return '' ;
27+ }
28+
29+ export function grantIOSCameraPermission ( appIdParam ?: string ) {
30+ if ( typeof driver === 'undefined' || ! driver . isIOS ) return ;
31+ const appId = appIdParam ?? getAppId ( ) ;
32+ const udid = getIosSimulatorUdidForSimctl ( ) ;
33+ if ( ! udid ) {
34+ console . warn ( '⚠ grantIOSCameraPermission: could not resolve simulator UDID' ) ;
35+ return ;
36+ }
37+ try {
38+ execSync ( `xcrun simctl privacy "${ udid } " grant camera "${ appId } "` , { stdio : 'ignore' } ) ;
39+ console . info ( `→ Granted iOS camera permission for '${ appId } ' (simulator ${ udid } )` ) ;
40+ } catch ( error ) {
41+ console . warn ( '⚠ grantIOSCameraPermission failed' , error ) ;
42+ }
43+ }
44+
745export async function launchFreshApp ( ) {
846 const appId = getAppId ( ) ;
947
@@ -23,6 +61,7 @@ export async function reinstallApp() {
2361 await driver . removeApp ( appId ) ;
2462 resetBootedIOSKeychain ( ) ;
2563 await driver . installApp ( appPath ) ;
64+ grantIOSCameraPermission ( appId ) ;
2665 await driver . activateApp ( appId ) ;
2766}
2867
@@ -52,6 +91,7 @@ export async function reinstallAppFromPath(appPath: string, appId: string = getA
5291 await driver . removeApp ( appId ) ;
5392 resetBootedIOSKeychain ( ) ;
5493 await driver . installApp ( appPath ) ;
94+ grantIOSCameraPermission ( appId ) ;
5595 await driver . activateApp ( appId ) ;
5696}
5797
0 commit comments