From a5ceed01d1055705552b14dc45bea233a436dac3 Mon Sep 17 00:00:00 2001 From: Dario Lencina Date: Sun, 8 Nov 2026 17:53:32 -0800 Subject: [PATCH 1/2] Manual exposure on variable-aperture lenses: no more crash on iPhone 18 Pro setExposureModeCustom(duration:iso:) locks the aperture too, and the iPhone 18 Pro refuses aperture + shutter + ISO all locked: the call raised an NSInvalidArgumentException and killed the app. The format now says which custom mode it takes (iOS 27 supportsExposureModeCustom(lensAperture:...)): all locked keeps the old call, shutter + ISO locked with auto aperture uses setExposureModeCustom(lensAperture: .auto, ...), and neither reports no Manual so the director offers bias only. The iOS 27 calls sit behind #if compiler(>=6.4) so the Xcode 26.2 CI build compiles; that build keeps the old behavior. Co-Authored-By: Claude Opus 5.5 --- RemoteCam/CaptureEngine.swift | 66 ++++++++++++++++++-- RemoteCamTests/CaptureIntegrationTests.swift | 3 +- 2 files changed, 62 insertions(+), 7 deletions(-) diff --git a/RemoteCam/CaptureEngine.swift b/RemoteCam/CaptureEngine.swift index 8065ae24..05ac8f96 100644 --- a/RemoteCam/CaptureEngine.swift +++ b/RemoteCam/CaptureEngine.swift @@ -1293,7 +1293,7 @@ final class CaptureEngine: NSObject, AVCapturePhotoCaptureDelegate { private func exposureFactsLocked(_ device: AVCaptureDevice) -> ExposureFacts { let format = device.activeFormat return ExposureFacts( - supportsCustom: device.isExposureModeSupported(.custom), + supportsCustom: Self.runsManual(device), minDurationSeconds: CMTimeGetSeconds(format.minExposureDuration), maxDurationSeconds: CMTimeGetSeconds(format.maxExposureDuration), minISO: format.minISO, @@ -1378,11 +1378,59 @@ final class CaptureEngine: NSObject, AVCapturePhotoCaptureDelegate { if CMTimeCompare(duration, format.minExposureDuration) < 0 { duration = format.minExposureDuration } if CMTimeCompare(duration, format.maxExposureDuration) > 0 { duration = format.maxExposureDuration } let safeISO = min(max(iso, format.minISO), format.maxISO) - device.setExposureModeCustom(duration: duration, iso: safeISO, completionHandler: done) + switch Self.manualAperture(for: format) { + case .locked: + device.setExposureModeCustom(duration: duration, iso: safeISO, completionHandler: done) + case .auto: + Self.setManualExposureWithAutoAperture(device, duration: duration, iso: safeISO, completion: done) + case nil: + // Never call a custom mode the format refuses: it raises an + // NSInvalidArgumentException that Swift cannot catch. + debugLog("🌗 EXPOSURE: \(device.localizedName) refuses locked shutter + ISO — staying auto") + exposureIntent = .auto(bias: 0) + completion?() + return + } debugLog("🌗 EXPOSURE: manual \(CMTimeGetSeconds(duration))s ISO \(safeISO) on \(device.localizedName)") } } + /// How Manual (shutter + ISO locked) runs on a format. `.locked` also + /// locks the aperture, the only option before variable-aperture lenses. + /// A variable-aperture lens (iPhone 18 Pro) refuses all three locked but + /// accepts shutter + ISO locked with the aperture left to auto exposure. + /// Nil = the format takes neither, so Manual is not offered. + enum ManualAperture: Equatable { case locked, auto } + + static func manualAperture(for format: AVCaptureDevice.Format) -> ManualAperture? { + #if compiler(>=6.4) + if #available(iOS 27.0, macCatalyst 27.0, *) { + let locked = format.supportsExposureModeCustom( + lensAperture: AVCaptureDevice.currentLensAperture, + duration: AVCaptureDevice.currentExposureDuration, iso: AVCaptureDevice.currentISO) + if locked { return .locked } + let autoAperture = format.supportsExposureModeCustom( + lensAperture: AVCaptureDevice.autoLensAperture, + duration: AVCaptureDevice.currentExposureDuration, iso: AVCaptureDevice.currentISO) + return autoAperture ? .auto : nil + } + #endif + return .locked + } + + private static func setManualExposureWithAutoAperture( + _ device: AVCaptureDevice, duration: CMTime, iso: Float, completion: ((CMTime) -> Void)? + ) { + #if compiler(>=6.4) + if #available(iOS 27.0, macCatalyst 27.0, *) { + device.setExposureModeCustom(lensAperture: AVCaptureDevice.autoLensAperture, + duration: duration, iso: iso, completionHandler: completion) + return + } + #endif + completion?(.invalid) + } + /// The lens Manual exposure runs on: the device itself when it accepts /// `.custom`; for a virtual device (which refuses it), a constituent that /// does — the active one while the session runs, else the wide lens. @@ -1392,15 +1440,21 @@ final class CaptureEngine: NSObject, AVCapturePhotoCaptureDelegate { /// used in a RUNNING session, and the first state exchange happens before /// the session starts. private func manualExposureLensLocked(for device: AVCaptureDevice) -> AVCaptureDevice? { - if device.isExposureModeSupported(.custom) { return device } + if Self.runsManual(device) { return device } guard device.isVirtualDevice else { return nil } - if let active = device.activePrimaryConstituent, active.isExposureModeSupported(.custom) { + if let active = device.activePrimaryConstituent, Self.runsManual(active) { return active } - let candidates = device.constituentDevices.filter { $0.isExposureModeSupported(.custom) } + let candidates = device.constituentDevices.filter { Self.runsManual($0) } return candidates.first { $0.deviceType == .builtInWideAngleCamera } ?? candidates.first } + /// The device takes `.custom` and its active format accepts shutter + ISO + /// locked, with the aperture locked or left to auto exposure. + private static func runsManual(_ device: AVCaptureDevice) -> Bool { + device.isExposureModeSupported(.custom) && manualAperture(for: device.activeFormat) != nil + } + /// The physical lens `device` must run on for Manual, or nil when it can /// run Manual itself (or Manual is off). Two entry points act on it — a /// change of intent (`reconcileExposureDeviceLocked`) and a change of @@ -1408,7 +1462,7 @@ final class CaptureEngine: NSObject, AVCapturePhotoCaptureDelegate { /// `swapToDeviceLocked` calls `applyExposureIntentLocked`, so a swap from /// there would recurse. private func manualExposureHopTargetLocked(for device: AVCaptureDevice) -> AVCaptureDevice? { - guard case .manual = exposureIntent, !device.isExposureModeSupported(.custom) else { return nil } + guard case .manual = exposureIntent, !Self.runsManual(device) else { return nil } return manualExposureLensLocked(for: device) } diff --git a/RemoteCamTests/CaptureIntegrationTests.swift b/RemoteCamTests/CaptureIntegrationTests.swift index 0ec2f683..ec6138cf 100644 --- a/RemoteCamTests/CaptureIntegrationTests.swift +++ b/RemoteCamTests/CaptureIntegrationTests.swift @@ -200,7 +200,8 @@ final class CaptureIntegrationTests: XCTestCase { let manual = await rig.gatherCurrentCameraCapabilities() XCTAssertEqual(manual?.exposure?.mode, .manual) XCTAssertEqual(manual?.exposure?.durationSeconds ?? 0, 1.0 / 250, accuracy: 1.0 / 2000) - XCTAssertEqual(manual?.exposure?.iso ?? 0, min(400, before.maxISO), accuracy: 1) + // Within 1%: the iPhone 18 Pro lands 400 as 398.77 (its gain steps). + XCTAssertEqual(manual?.exposure?.iso ?? 0, min(400, before.maxISO), accuracy: min(400, before.maxISO) / 100) XCTAssertEqual(manual?.activeDeviceID, logicalBefore, "a lens hop never leaks into the logical device") print("🌗 probe: manual landed — \(manual?.exposure.map { "\($0)" } ?? "nil") active=\(manual?.activeDeviceID ?? "?")") From 7a899499e38d460da4bab40cae6a6fac35acc8cf Mon Sep 17 00:00:00 2001 From: Dario Lencina Date: Sun, 8 Nov 2026 17:59:39 -0800 Subject: [PATCH 2/2] CI and release on Xcode 27.1, so the variable-aperture fix ships The fix needs the iOS 27 SDK. Build, Catalyst and the App Store release move from macos-26 / Xcode 26.2 to GitHub's xcode-27 image with Xcode 27.1 (a release build, which App Store Connect accepts), tests on the iOS 27.0 iPhone 17 simulator. Compilation caches are keyed per Xcode version. With the SDK guaranteed, the #if compiler guard goes: a missing API now fails the build instead of silently dropping the fix. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/ios-ci.yml | 22 +++++++++++----------- .github/workflows/release.yml | 4 ++-- RemoteCam/CaptureEngine.swift | 4 ---- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/.github/workflows/ios-ci.yml b/.github/workflows/ios-ci.yml index 8628a969..7209e7b0 100644 --- a/.github/workflows/ios-ci.yml +++ b/.github/workflows/ios-ci.yml @@ -13,7 +13,7 @@ permissions: jobs: build: name: Build and Test - runs-on: macos-26 + runs-on: xcode-27 steps: - name: Checkout @@ -24,7 +24,7 @@ jobs: - name: Setup Xcode uses: maxim-lobanov/setup-xcode@v1 with: - xcode-version: '26.2' + xcode-version: '27.1' - name: Show Xcode version run: xcodebuild -version @@ -32,16 +32,16 @@ jobs: - name: Show available simulators run: xcrun simctl list devicetypes - # Xcode 26 compilation cache (LLVM CAS). Content-addressed, so stale + # Xcode compilation cache (LLVM CAS), one per Xcode version. Content-addressed, so stale # entries are harmless — restore-keys falls back to the newest cache on # any branch when the exact-sha key misses (i.e. always, except re-runs). - name: Restore compilation cache uses: actions/cache@v4 with: path: ~/compilation-cache - key: cas-ios-${{ github.sha }} + key: cas-ios-xcode27.1-${{ github.sha }} restore-keys: | - cas-ios- + cas-ios-xcode27.1- # TODO: Remove this once we have a way to install CocoaPods # - name: Cache CocoaPods @@ -66,7 +66,7 @@ jobs: xcodebuild \ -workspace RemoteShutter.xcworkspace \ -scheme RemoteCam \ - -destination 'platform=iOS Simulator,OS=26.2,name=iPhone 17' \ + -destination 'platform=iOS Simulator,OS=27.0,name=iPhone 17' \ -configuration Debug \ clean build \ CODE_SIGNING_REQUIRED=NO \ @@ -85,7 +85,7 @@ jobs: xcodebuild \ -workspace RemoteShutter.xcworkspace \ -scheme RemoteCam \ - -destination 'platform=iOS Simulator,OS=26.2,name=iPhone 17' \ + -destination 'platform=iOS Simulator,OS=27.0,name=iPhone 17' \ -configuration Debug \ test \ -enableCodeCoverage YES \ @@ -133,7 +133,7 @@ jobs: build-mac-catalyst: name: Build Mac Catalyst - runs-on: macos-26 + runs-on: xcode-27 steps: - name: Checkout @@ -144,15 +144,15 @@ jobs: - name: Setup Xcode uses: maxim-lobanov/setup-xcode@v1 with: - xcode-version: '26.2' + xcode-version: '27.1' - name: Restore compilation cache uses: actions/cache@v4 with: path: ~/compilation-cache - key: cas-catalyst-${{ github.sha }} + key: cas-catalyst-xcode27.1-${{ github.sha }} restore-keys: | - cas-catalyst- + cas-catalyst-xcode27.1- - name: Build for Mac Catalyst run: | diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index ea9dbd80..f478065f 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -23,7 +23,7 @@ permissions: jobs: release: name: Build & Upload to App Store - runs-on: macos-26 + runs-on: xcode-27 steps: - uses: actions/checkout@v4 with: @@ -31,7 +31,7 @@ jobs: - uses: maxim-lobanov/setup-xcode@v1 with: - xcode-version: '26.2' + xcode-version: '27.1' - uses: ruby/setup-ruby@v1 with: diff --git a/RemoteCam/CaptureEngine.swift b/RemoteCam/CaptureEngine.swift index 05ac8f96..46c112cb 100644 --- a/RemoteCam/CaptureEngine.swift +++ b/RemoteCam/CaptureEngine.swift @@ -1403,7 +1403,6 @@ final class CaptureEngine: NSObject, AVCapturePhotoCaptureDelegate { enum ManualAperture: Equatable { case locked, auto } static func manualAperture(for format: AVCaptureDevice.Format) -> ManualAperture? { - #if compiler(>=6.4) if #available(iOS 27.0, macCatalyst 27.0, *) { let locked = format.supportsExposureModeCustom( lensAperture: AVCaptureDevice.currentLensAperture, @@ -1414,20 +1413,17 @@ final class CaptureEngine: NSObject, AVCapturePhotoCaptureDelegate { duration: AVCaptureDevice.currentExposureDuration, iso: AVCaptureDevice.currentISO) return autoAperture ? .auto : nil } - #endif return .locked } private static func setManualExposureWithAutoAperture( _ device: AVCaptureDevice, duration: CMTime, iso: Float, completion: ((CMTime) -> Void)? ) { - #if compiler(>=6.4) if #available(iOS 27.0, macCatalyst 27.0, *) { device.setExposureModeCustom(lensAperture: AVCaptureDevice.autoLensAperture, duration: duration, iso: iso, completionHandler: completion) return } - #endif completion?(.invalid) }