Skip to content

Conversation

@fabiomartino
Copy link
Contributor

This PR updates the plugin to support Capacitor v8. The migration follows the official Capacitor v8 plugin upgrade guide.

This update addresses build issues on Android and specifically fixes compilation errors on iOS introduced by the stricter Swift Package Manager (SPM) integration in Capacitor v8.

Key Changes

📱 iOS (Swift & SPM)

The transition to Capacitor v8 and its default usage of Swift Package Manager required several adjustments in CameraPreviewPlugin.swift and CameraController.swift:

  1. SPM Compatibility (reject vs resolve):
  • In the Capacitor v8 SPM toolchain, call.reject() is not reliably exposed or callable in the same way as CocoaPods.
  • Fix: Replaced calls to call.reject("message") with a state-based resolution pattern: call.resolve(["success": false, "error": "message"]). This ensures the plugin compiles and behaves consistently across toolchains.
  1. Strict Type Safety & Optionals:
  • Updated how optional values (e.g., getInt, getString) are retrieved. Capacitor v8 accessors now enforce strict non-optional returns in certain contexts.
  • Fix: Implemented safer unwrapping using call.options["key"] or provided explicit default values where appropriate to prevent runtime crashes and build errors.
  1. API Deprecations:
  • Fix: Replaced the deprecated UIApplication.shared.statusBarOrientation (iOS 13+) with modern UIWindowScene logic to correctly determine interface orientation.

📦 Dependencies (NPM)

  • Bumped @capacitor/core, @capacitor/android, and @capacitor/ios to ^8.0.0.
  • Note on installation: I noticed the package.json contains specific overrides for ESLint versions. To respect your current configuration and avoid altering the repository's architecture or linting rules, I utilized npm install --force to resolve the peer dependency graph. You may want to review the overrides section in a future maintenance update to align it with the newer TypeScript/ESLint ecosystem, but for now, I have left it as is to minimize friction.

⚠️ Important testing note

This PR has been tested locally on both Android and iOS.
However, since this plugin interacts with system-level settings and behavior can vary
between devices and OS versions, it is strongly recommended that the original maintainer
also tests these changes in their own environment before approving and releasing.
No breaking changes are introduced beyond the already required Capacitor 8 migration.

- Replace deprecated `UIApplication.shared.statusBarOrientation` with `UIWindowScene` logic.
- Replace deprecated `jpegPhotoDataRepresentation` with `fileDataRepresentation`.
- Fix logic bug in `UIImage.fixedOrientation` where transform results were unused.
- Fix various linter issues.
@fabiomartino
Copy link
Contributor Author

reopen

@fabiomartino fabiomartino reopened this Jan 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant