@@ -93,34 +93,24 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
9393 return launchResult ;
9494 }
9595
96- public async stopApplication ( deviceId : string , appIdentifier : string , bundleExecutable : string ) : Promise < string > {
96+ public async stopApplication ( deviceId : string , appIdentifier : string , bundleExecutable : string ) : Promise < void > {
9797 try {
98- let xcodeMajorVersion : number = null ;
99- try {
100- const xcodeVersion = xcode . getXcodeVersionData ( ) ;
101- xcodeMajorVersion = + xcodeVersion . major ;
102- } catch ( err ) {
103- // Ignore the error.
104- }
105-
106- let resultOfTermination : string ;
107- if ( xcodeMajorVersion && xcodeMajorVersion < 8 ) {
108- // Xcode 7.x does not have support for `xcrun simctl terminate` command
109- resultOfTermination = childProcess . execSync ( `killall ${ bundleExecutable } ` , { skipError : true } ) ;
110- } else {
111- resultOfTermination = await this . simctl . terminate ( deviceId , appIdentifier ) ;
98+ let pid = this . getPid ( deviceId , bundleExecutable ) ;
99+ while ( pid ) {
100+ childProcess . execSync ( `kill -9 ${ pid } ` , { skipError : true } ) ;
101+ pid = this . getPid ( deviceId , bundleExecutable ) ;
102+ if ( pid ) {
103+ utils . sleep ( 0.1 ) ;
104+ }
112105 }
113-
114- // killall command does not terminate the processes immediately and we have to wait a little bit,
115- // just to ensure all related processes and services are dead.
116- // Same is valid for simctl terminate when Simulator's OS version is below 10.
117- utils . sleep ( 0.5 ) ;
118-
119- return resultOfTermination ;
120106 } catch ( e ) {
121107 }
122108 }
123109
110+ private getPid ( deviceId : string , bundleExecutable : string ) : string {
111+ return childProcess . execSync ( `ps -ef | grep ${ bundleExecutable } | grep ${ deviceId } | grep -v grep | awk '{print $2}'` , { skipError : true } ) . toString ( ) . trim ( ) ;
112+ }
113+
124114 public async getDeviceLogProcess ( deviceId : string , predicate ?: string ) : Promise < child_process . ChildProcess > {
125115 const device = await this . getDeviceFromIdentifier ( deviceId ) ;
126116 return new Promise < child_process . ChildProcess > ( ( resolve , reject ) => {
0 commit comments