Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix focus and camera handling for newer iOS devices with triple cameras (+ other fixes) #342

Closed
wants to merge 30 commits into from

Conversation

michaelwolz
Copy link

@michaelwolz michaelwolz commented Jul 8, 2024

Overview

This PR fixes several open issues, particularly on iOS, by addressing problems related to newer iOS devices with triple cameras (iPhone 14 Pro and later). Also this PR cleans up the iOS code, removes dead code and updates deprecated function calls that triggered warnings.

We are currently using this adapted version of the plugin in our app and it works perfectly fine for us. I don't know if this plugin is still actively maintained or not but I appreciate any feedback and am also willing to do adaptions if this is necessary to get it merged into the official codebase.

Changes

  • Switched to using the virtual builtInTripleCamera, which automatically switches between the three lenses based on the focused object.
  • Set the initial zoom factor to 2 for the builtInTripleCamera to avoid the default use of the ultra-wide-angle lens, which can cause a "fisheye" effect. This zoom factor matches the "1x" setting of the native camera app.
  • Cleaned up camera initialization logic by restructuring the code (this was done to improve performance when starting the capture session)
  • Make high resolution mode work on iOS by using dedicated AVCaptureSession preset photo
  • Throw an error when calling startRecordVideo() or stopRecordVideo() on iOS and adapted the readme accordingly. This was not implemented even though documentation says it is. I think it's better to fully remove this from the code and refer to another solution such as: https://github.com/capacitor-community/video-recorder. I'd wish I would have a better solution but since I am not using this feature I decided to just change the current behvior to not confuse devs that call these methods and expect any output from it (also unnecessarily adding the DataOutput for the video capture was slowing down starting the camera by a lot).
  • Placed the camera preview overlay on the correct position when using x and y coordinates
  • Added checkPermissions and requestPermissions method for iOS
  • Fixed rotation logic of images on Android
  • Added some documentation to the code (iOS)

Resolved Issues

Note: I just saw that #339 also updates to the new Camera v2 API which would be even better due to many deprecation warnings with the old code but still this PR will fix the rotation logic with the old API

@michaelwolz michaelwolz changed the title Fix Focus and Camera Handling for Newer iOS Devices with Triple Cameras (and other fixes) Fix focus and camera handling for newer iOS devices with triple cameras (+ other fixes) Jul 8, 2024
@@ -0,0 +1,56 @@
extension UIImage {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was just moved to a separate file. Was previously located in CameraController.swift

@florianleger
Copy link

It seems that the captureSample method does not work (when I call it, I never get the response or error).
Otherwise, the focus fix works just fine!

@michaelwolz
Copy link
Author

@florianleger hm, yes probably [due to the removal of the AVCaptureVideoDataOutput which I did because of severe performance problems with handling multiple outputs.

In theory we might make this an optional feature which can be enabled via some flag and then configures a DataOutput again 🤔

@michaelwolz
Copy link
Author

Since I did quite a lot of opinionated changes to the code I decided to publish a lite version of the plugin on my own until further development goes on with the official version :).

Feel free to use my version as long as you just want to take photos and do not require video recordings etc: https://github.com/michaelwolz/camera-preview-lite

@selected-pixel-jameson
Copy link

@michaelwolz THANK YOU!!!!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants