diff --git a/bp/src/BPSimulator.m b/bp/src/BPSimulator.m index 04c29ca8..b9367258 100644 --- a/bp/src/BPSimulator.m +++ b/bp/src/BPSimulator.m @@ -127,7 +127,7 @@ - (NSString *)installApplicationWithHost:(NSString *)testHost withError:(NSError }]; return nil; } else { - [self shutdownSimulatorWithError:errPtr]; + [self shutdownSimulator:simDevice withError:errPtr]; if(*errPtr) { [BPUtils printInfo:ERROR withString:@"Shutdown simulator failed with error: %@", [*errPtr localizedDescription]]; [deviceSet deleteDeviceAsync:simDevice completionHandler:^(NSError *error) { @@ -307,17 +307,20 @@ - (BOOL)useSimulatorWithDeviceUDID:(NSUUID *)deviceUDID { return YES; } -- (BOOL)shutdownSimulatorWithError:(id *)error { - [BPUtils printInfo:INFO withString:@"Starting Safe Shutdown of %@", self.device.UDID.UUIDString]; +- (BOOL)shutdownSimulator:(SimDevice *)simDevice withError:(id *)error { + if (!simDevice) { + return NO; + } + [BPUtils printInfo:INFO withString:@"Starting Safe Shutdown of %@", simDevice.UDID.UUIDString]; // Calling shutdown when already shutdown should be avoided (if detected). - if ([self.device.stateString isEqualToString:@"Shutdown"]) { - [BPUtils printInfo:INFO withString:@"Shutdown of %@ succeeded as it is already shutdown", self.device]; + if ([simDevice.stateString isEqualToString:@"Shutdown"]) { + [BPUtils printInfo:INFO withString:@"Shutdown of %@ succeeded as it is already shutdown", simDevice]; *error = nil; return YES; } - return [self.device shutdownWithError:error]; + return [simDevice shutdownWithError:error]; } - (void)bootWithCompletion:(void (^)(NSError *error))completion { @@ -333,7 +336,7 @@ - (void)openSimulatorHeadlessWithCompletion:(void (^)(NSError *))completion { [self.device bootAsyncWithOptions:options completionHandler:^(NSError *bootError){ NSError *error = [self waitForDeviceReady]; if (error) { - [self shutdownSimulatorWithError:&error]; + [self shutdownSimulator:self.device withError:&error]; if (error) { [BPUtils printInfo:ERROR withString:@"Shutting down Simulator failed: %@", [error localizedDescription]]; } @@ -584,7 +587,7 @@ - (void)deleteSimulatorWithCompletion:(void (^)(NSError *error, BOOL success))co } if (self.device) { [BPUtils printInfo:INFO withString:@"Shutting down Simulator"]; - [self shutdownSimulatorWithError:&error]; + [self shutdownSimulator:self.device withError:&error]; if (error) { [BPUtils printInfo:ERROR withString:@"Shutting down Simulator failed: %@", [error localizedDescription]]; completion(error, NO);