By 2025 the app had two capture paths, a working depth pipeline, and enough testers that changing a setting meant shipping a build. Field use kept calling for a different interval, a different lens, or the other camera type.

I added a settings sheet inside the app, and while building it I introduced a white balance bug.

What the screen needed to do

Three settings used to require a code change and a rebuild:

  • Camera type: ARKit or AVFoundation, chosen per session.
  • Capture timing: the interval for continuous capture.
  • Lens selection: which physical camera AVFoundation should use.
Camera settings sheet with ARKit selected, a capture timing slider, and a lens list
The first version: camera type, timing, and lens. The white balance section did not exist yet.
Camera settings sheet with AVFoundation selected and the LiDAR depth camera marked as current
The same sheet with AVFoundation selected. The lens list only applies to that path, so it is labelled accordingly.

The layout is simple because the phone is held at arm’s length over a plot. A segmented control at the top and a slider below it are about all that can be operated in that position.

Final settings sheet including a white balance section with Auto, Daylight, Tungsten, Fluorescent, and Locked options
The final sheet, after the white balance section was added. It sits between the timing slider and the lens list because it affects both capture paths.

Persisting the selection is plain UserDefaults, keyed by setting name, read once when the capture session is configured:

enum CameraSettingKey {
    static let cameraType = "cameraType"          // "ARKit" | "AVFoundation"
    static let captureInterval = "captureInterval" // seconds
    static let lens = "lensSelection"              // AVCaptureDevice.DeviceType name
    static let whiteBalance = "whiteBalanceMode"
}

Capture timing

The slider sets how often the app captures while the record button is held. At 0.10 s it behaves like a burst; at a second or more it is a sampling tool for walking a transect.

Settings sheet showing a capture interval of 1.12 seconds
1.12 s: one capture per position, for walking a row.
Main screen at 0.50 seconds with the camera preview area black
0.50 s. The preview is black here because the session had not started; the timing label updates independently of the camera state.

Two problems in this part of the rebuild showed up on screen.

The first is the black preview above. The timing control and the capture session were updated by separate code paths, so the label could show a new interval while the session was still stopped. Nothing was captured, and the app gave no warning.

The second is the layout. In the screenshot below the preview area is empty except for the bottom half, the ARKit switch is squeezed next to the slider, and the settings button is clipped to ...ings:

Main screen with an ARKit toggle, a timing slider, and a clipped settings button label
An intermediate layout: the ARKit toggle crowded the timing slider, and the settings button lost its label. After this, I moved the controls into a sheet.

The final layout moved capture and settings into their own row and dropped the toggle, since the camera type now lives in the sheet:

Main screen with a dedicated Capture button, an emulator button, and the RGB, thermal, depth, and confidence panels
The rebuilt screen: one large Capture button, the thermal and depth pairs below it, and the GPS and weather readout pinned at the bottom.

The green cast

RGB captures came back with a strong green tint. It was obvious in the file browser and even more obvious on a white reference surface.

iOS file browser showing a grid of captures, all with a heavy green cast
Every capture from that session, green. The tint was consistent across files, which ruled out a per-frame artefact.

The tint was in the saved JPEG, not only in the preview, so the pipeline was writing the wrong colours to disk. A capture on the same phone with the native camera app, a minute later, was neutral. So the cause was the capture configuration, not the sensor or the scene.

App preview showing a green-tinted camera image next to a white panel
The live preview with the same cast. The preview and the saved file show the same cast, so the bug is in the pipeline, not the viewer.

The cast came from the manual white balance control I was adding to the sheet. The locked gains the app applied while I was adjusting it were wrong, and every capture after that inherited them.

The fix was to default to continuous auto white balance, and when a fixed mode is chosen, to compute the gains from a preset and clamp them to the device maximum before locking:

try device.lockForConfiguration()

if device.isWhiteBalanceModeSupported(.continuousAutoWhiteBalance) {
    device.whiteBalanceMode = .continuousAutoWhiteBalance
}

// or, for a fixed reference card at the start of a session
if device.isWhiteBalanceModeSupported(.locked) {
    let gains = device.deviceWhiteBalanceGains(for: .daylight)
    let maxGain = device.maxWhiteBalanceGain
    let clamped = AVCaptureDevice.WhiteBalanceGains(
        redGain: min(gains.redGain, maxGain),
        greenGain: min(gains.greenGain, maxGain),
        blueGain: min(gains.blueGain, maxGain)
    )
    device.setWhiteBalanceModeLocked(with: clamped)
}

device.unlockForConfiguration()

I kept the control in the sheet. Locking white balance against a reference card at the start of a session is more repeatable across plots than auto white balance, which helps when RGB is analyzed together with thermal and depth.

The two files side by side:

Two versions of the same capture side by side in Preview, the left green and the right neutral
Same frame, before and after the white balance fix. Only the colour pipeline changed.

What a capture costs in storage

At full still resolution each JPEG is 3024×4032 and about 2.8 MB:

Finder Get Info window showing a 2.8 MB JPEG at 3024 by 4032 pixels, sRGB
One RGB frame: 2.8 MB, 3024×4032, sRGB. Add the FLIR JPEG and the two TIFFs and a single capture is roughly 10 MB.

At 0.10 s a plot walk generates a few hundred megabytes, and the phone has to write them while the thermal stream is still running. So the interval also controls storage and write load.

Still crashing in the thermal path

The 2025 build still crashed, and the reports pointed at the thermal SDK again, this time inside vendor code with no symbols:

Xcode Organizer crash report for ThermalSDK with an unresolved address offset, distributed through TestFlight
Xcode Organizer, one crash, one device, distributed through TestFlight. The whole stack is inside ThermalSDK at an unresolved offset.

The practical workaround came from FLIR’s own app rather than from documentation. The FLIR ONE app exposes two modes:

FLIR ONE app in Quality Mode, showing a thermal view of a desk
Quality Mode: slower updates, better image.
FLIR ONE app in Performance Mode, showing the same scene with a coarser thermal image
Performance Mode: more responsive, visibly coarser.

FLIR’s support page describes the trade as “Quality Mode for best possible image quality, or Performance Mode for a more responsive camera experience”. Their app can switch because it does not also have to hold depth frames, write TIFFs, and read a BLE weather station on the same queue. At a 0.10 s interval our app asks the thermal SDK for stills at that rate, which the pipeline cannot sustain. The workaround is to keep the interval longer.

One item is still open: add a weather station connection flag to the JSON. Right now a missing reading and a zero reading look identical in the metadata.

References