Skip to content

bug(ios): Camera crash on iOS 16–17 due to deprecated AVCaptureVideoOrientation API #42

Description

@bohdanovdmytro

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:

  1. AVCaptureVideoOrientation → use AVCaptureDevice.RotationCoordinator (iOS 17+) with a fallback to AVCaptureVideoOrientation for iOS < 17
  2. UIWindowScene.windowsUIWindowScene.keyWindow (iOS 15+)
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions