Description
When opening the barcode scanner, the app crashes immediately on devices running iOS 16 and iOS 17. The same devices work correctly after updating to iOS 18.
Affected devices
| Device |
iOS Version |
Result |
| iPhone 8 Pro Max |
16.7.14 |
Crash |
| iPhone SE (Gen 2/3) |
17.5.1 |
Crash |
| iPhone 13 |
17.2.1 |
Crash |
Root cause
The library uses AVCaptureVideoOrientation and videoPreviewLayer.connection?.videoOrientation which were deprecated in iOS 17.0. These are used in two places in OSBARCCaptureSessionManager.swift:
1. setup(type:) method — sets initial video orientation:
videoPreviewLayer.connection?.videoOrientation = initialVideoOrientation
2. apply(change:) method — updates orientation on rotation:
videoPreviewLayer.connection?.videoOrientation = newVideoOrientation
Both rely on:
AVCaptureVideoOrientation (deprecated iOS 17.0)
AVCaptureConnection.videoOrientation (deprecated iOS 17.0)
Additionally:
UIApplication+Window.swift uses UIWindowScene.windows (deprecated iOS 15.0) instead of UIWindowScene.keyWindow
View+CustomModifiers.swift uses onChange(of:perform:) (deprecated iOS 17.0) without an #available check for the new iOS 17+ variant
Suggested fix
Replace deprecated APIs with their modern equivalents:
AVCaptureVideoOrientation → use AVCaptureDevice.RotationCoordinator (iOS 17+) with a fallback to AVCaptureVideoOrientation for iOS < 17
UIWindowScene.windows → UIWindowScene.keyWindow (iOS 15+)
onChange(of:perform:) → add #available(iOS 17.0, *) check and use the new onChange(of:initial:_:) variant
Environment
OSBarcodeLib: 2.0.1
@capacitor/barcode-scanner: 3.0.2
- Minimum deployment target: iOS 15.0
Related: ionic-team/capacitor-barcode-scanner#118
Description
When opening the barcode scanner, the app crashes immediately on devices running iOS 16 and iOS 17. The same devices work correctly after updating to iOS 18.
Affected devices
Root cause
The library uses
AVCaptureVideoOrientationandvideoPreviewLayer.connection?.videoOrientationwhich were deprecated in iOS 17.0. These are used in two places inOSBARCCaptureSessionManager.swift:1.
setup(type:)method — sets initial video orientation:2.
apply(change:)method — updates orientation on rotation:Both rely on:
AVCaptureVideoOrientation(deprecated iOS 17.0)AVCaptureConnection.videoOrientation(deprecated iOS 17.0)Additionally:
UIApplication+Window.swiftusesUIWindowScene.windows(deprecated iOS 15.0) instead ofUIWindowScene.keyWindowView+CustomModifiers.swiftusesonChange(of:perform:)(deprecated iOS 17.0) without an#availablecheck for the new iOS 17+ variantSuggested fix
Replace deprecated APIs with their modern equivalents:
AVCaptureVideoOrientation→ useAVCaptureDevice.RotationCoordinator(iOS 17+) with a fallback toAVCaptureVideoOrientationfor iOS < 17UIWindowScene.windows→UIWindowScene.keyWindow(iOS 15+)onChange(of:perform:)→ add#available(iOS 17.0, *)check and use the newonChange(of:initial:_:)variantEnvironment
OSBarcodeLib: 2.0.1@capacitor/barcode-scanner: 3.0.2Related: ionic-team/capacitor-barcode-scanner#118