Skip to content

Commit a8e6c33

Browse files
committed
Pass simDevice to the shutdown method (#561)
Signed-off-by: Nan Wang <nanwang1101@yahoo.com>
1 parent d14d127 commit a8e6c33

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

bp/src/BPSimulator.m

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ - (NSString *)installApplicationWithHost:(NSString *)testHost withError:(NSError
127127
}];
128128
return nil;
129129
} else {
130-
[self shutdownSimulatorWithError:errPtr];
130+
[self shutdownSimulator:simDevice withError:errPtr];
131131
if(*errPtr) {
132132
[BPUtils printInfo:ERROR withString:@"Shutdown simulator failed with error: %@", [*errPtr localizedDescription]];
133133
[deviceSet deleteDeviceAsync:simDevice completionHandler:^(NSError *error) {
@@ -307,17 +307,20 @@ - (BOOL)useSimulatorWithDeviceUDID:(NSUUID *)deviceUDID {
307307
return YES;
308308
}
309309

310-
- (BOOL)shutdownSimulatorWithError:(id *)error {
311-
[BPUtils printInfo:INFO withString:@"Starting Safe Shutdown of %@", self.device.UDID.UUIDString];
310+
- (BOOL)shutdownSimulator:(SimDevice *)simDevice withError:(id *)error {
311+
if (!simDevice) {
312+
return NO;
313+
}
314+
[BPUtils printInfo:INFO withString:@"Starting Safe Shutdown of %@", simDevice.UDID.UUIDString];
312315

313316
// Calling shutdown when already shutdown should be avoided (if detected).
314-
if ([self.device.stateString isEqualToString:@"Shutdown"]) {
315-
[BPUtils printInfo:INFO withString:@"Shutdown of %@ succeeded as it is already shutdown", self.device];
317+
if ([simDevice.stateString isEqualToString:@"Shutdown"]) {
318+
[BPUtils printInfo:INFO withString:@"Shutdown of %@ succeeded as it is already shutdown", simDevice];
316319
*error = nil;
317320
return YES;
318321
}
319322

320-
return [self.device shutdownWithError:error];
323+
return [simDevice shutdownWithError:error];
321324
}
322325

323326
- (void)bootWithCompletion:(void (^)(NSError *error))completion {
@@ -333,7 +336,7 @@ - (void)openSimulatorHeadlessWithCompletion:(void (^)(NSError *))completion {
333336
[self.device bootAsyncWithOptions:options completionHandler:^(NSError *bootError){
334337
NSError *error = [self waitForDeviceReady];
335338
if (error) {
336-
[self shutdownSimulatorWithError:&error];
339+
[self shutdownSimulator:self.device withError:&error];
337340
if (error) {
338341
[BPUtils printInfo:ERROR withString:@"Shutting down Simulator failed: %@", [error localizedDescription]];
339342
}
@@ -584,7 +587,7 @@ - (void)deleteSimulatorWithCompletion:(void (^)(NSError *error, BOOL success))co
584587
}
585588
if (self.device) {
586589
[BPUtils printInfo:INFO withString:@"Shutting down Simulator"];
587-
[self shutdownSimulatorWithError:&error];
590+
[self shutdownSimulator:self.device withError:&error];
588591
if (error) {
589592
[BPUtils printInfo:ERROR withString:@"Shutting down Simulator failed: %@", [error localizedDescription]];
590593
completion(error, NO);

0 commit comments

Comments
 (0)