Skip to content

Commit

Permalink
Terminate app on iOS simulator before install to address iOS 18 change (
Browse files Browse the repository at this point in the history
  • Loading branch information
lfroms authored Sep 20, 2024
1 parent f40fcff commit b6ef2bf
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum SimCtlCommand {
case boot(device: String)
case install(device: String, bundleUrl: URL)
case launch(device: String, bundleIdentifier: String, arguments: [String])
case terminate(device: String, bundleIdentifier: String)
}

extension SimCtlCommand: ShellCommand {
Expand All @@ -47,6 +48,9 @@ extension SimCtlCommand: ShellCommand {

case .launch(let device, let bundleIdentifier, let arguments):
return ["simctl", "launch", device, bundleIdentifier] + arguments

case .terminate(let device, let bundleIdentifier):
return ["simctl", "terminate", device, bundleIdentifier]
}
}
}
3 changes: 3 additions & 0 deletions TophatModules/Sources/AppleDeviceKit/Simulator+Device.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@ extension Simulator: Device {

func install(application: Application) throws {
do {
// Failure to terminate is permitted as the application may not be running.
try? SimCtl.terminate(udid: id, bundleIdentifier: application.bundleIdentifier)

try SimCtl.install(udid: id, bundleUrl: application.url)
} catch {
throw DeviceError.failedToInstallApp(bundleUrl: application.url, deviceType: .virtual)
Expand Down
4 changes: 4 additions & 0 deletions TophatModules/Sources/AppleDeviceKit/Utilities/SimCtl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ final class SimCtl {
static func launch(udid: String, bundleIdentifier: String, arguments: [String]) throws {
try run(command: .simCtl(.launch(device: udid, bundleIdentifier: bundleIdentifier, arguments: arguments)), log: log)
}

static func terminate(udid: String, bundleIdentifier: String) throws {
try run(command: .simCtl(.terminate(device: udid, bundleIdentifier: bundleIdentifier)), log: log)
}
}

private extension Simulator {
Expand Down

0 comments on commit b6ef2bf

Please sign in to comment.