Skip to content

Commit 56a5c8d

Browse files
committed
feat: Add hardware-cost-too-high error for iOS 16
1 parent 28f0fb7 commit 56a5c8d

3 files changed

Lines changed: 16 additions & 0 deletions

File tree

package/ios/Core/CameraError.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ enum SessionError {
148148
case cameraNotReady
149149
case audioSessionFailedToActivate
150150
case audioInUseByOtherApp
151+
case hardwareCostTooHigh(cost: Float)
151152

152153
var code: String {
153154
switch self {
@@ -157,6 +158,8 @@ enum SessionError {
157158
return "audio-in-use-by-other-app"
158159
case .audioSessionFailedToActivate:
159160
return "audio-session-failed-to-activate"
161+
case .hardwareCostTooHigh:
162+
return "hardware-cost-too-high"
160163
}
161164
}
162165

@@ -168,6 +171,10 @@ enum SessionError {
168171
return "The audio session is already in use by another app with higher priority!"
169172
case .audioSessionFailedToActivate:
170173
return "Failed to activate Audio Session!"
174+
case let .hardwareCostTooHigh(cost: cost):
175+
return "The session's hardware-cost is too high! (Expected: <=1.0, Received: \(cost)) " +
176+
"See https://developer.apple.com/documentation/avfoundation/avcapturesession/3950869-hardwarecost " +
177+
"for more information."
171178
}
172179
}
173180
}

package/ios/Core/CameraSession.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,14 @@ class CameraSession: NSObject, AVCaptureVideoDataOutputSampleBufferDelegate, AVC
235235
}
236236
}
237237
}
238+
239+
// Check if Hardware Cost is okay
240+
if #available(iOS 16.0, *) {
241+
if self.captureSession.hardwareCost > 1 {
242+
// Throw this error to the user, but don't abort the configuration. Maybe it still works.
243+
self.onConfigureError(CameraError.session(.hardwareCostTooHigh(cost: self.captureSession.hardwareCost)))
244+
}
245+
}
238246
}
239247
}
240248

package/src/CameraError.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type SessionError =
2828
| 'session/audio-in-use-by-other-app'
2929
| 'session/no-outputs'
3030
| 'session/audio-session-failed-to-activate'
31+
| 'session/hardware-cost-too-high'
3132
| 'session/invalid-output-configuration'
3233
export type CodeScannerError =
3334
| 'code-scanner/not-compatible-with-outputs'

0 commit comments

Comments
 (0)