Further to Greg's reply to my solution, I confirm that builtInDualCamera does not provide close-focus, whereas builtInDualWideCamera does. I've therefore revised my solution (to support different iPhone / iPad models) as per below:
func getMacroDevice() -> AVCaptureDevice? {
if let device = AVCaptureDevice.default(.builtInTripleCamera,
for: .video, position: .back) {
return device
}
if let device = AVCaptureDevice.default(.builtInDualWideCamera,for: .video, position: .back) {
return device
}
if let device = AVCaptureDevice.default(for: .video) {
return device
}
return nil
}
I'm still puzzled by the "default behaviour" not working and will explore further at https://developer.apple.com/documentation/avfoundation/avcapturedevice/activeprimaryconstituentdeviceswitchingbehavior
UPDATE: using device = AVCaptureDevice.default(for: .video) and then getting that device's .primaryConstituentDeviceSwitchingBehavior returns .unsupported for my iPhone 15 Pro under iOS 18.3. So, it seems that our code must specify a primary constituent device, as per my code above, otherwise the default device does not qualify for switching, if available. Perhaps this is what Greg was getting at with his original answer.
Also, the M1 iPad Pro has a .builtInDualWideCamera, which is probably its default.
Regards, Michaela