@@ -93,34 +93,24 @@ export class XCodeSimctlSimulator extends IPhoneSimulatorNameGetter implements I
93
93
return launchResult ;
94
94
}
95
95
96
- public async stopApplication ( deviceId : string , appIdentifier : string , bundleExecutable : string ) : Promise < string > {
96
+ public async stopApplication ( deviceId : string , appIdentifier : string , bundleExecutable : string ) : Promise < void > {
97
97
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
+ }
112
105
}
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 ;
120
106
} catch ( e ) {
121
107
}
122
108
}
123
109
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
+
124
114
public async getDeviceLogProcess ( deviceId : string , predicate ?: string ) : Promise < child_process . ChildProcess > {
125
115
const device = await this . getDeviceFromIdentifier ( deviceId ) ;
126
116
return new Promise < child_process . ChildProcess > ( ( resolve , reject ) => {
0 commit comments