Plugin does not show camera preview on iOS after updating to iOS 15.4
See original GitHub issueDescribe the bug
All was working fine until I update my iPhone to iOS 15 (not sure which minor version started the problem), but now after call CameraPreview.start
method the camera preview doesn’t appear. The led that indicates the device is using the camera turns on and if I call CameraPreview.capture
method the picture is returned as expected but without showing the preview during all the process.
To Reproduce Steps to reproduce the behavior:
- Just start the camera preview.
Expected behavior
Show the camera preview when start
method is called.
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information):
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]
Smartphone (please complete the following information):
- Device: iPhone 11
- OS: iOS 15.4.1
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]
Additional context As I said, previously everything was working as expected. I didn’t change anything in the code regarding Camera Preview and I only noticed the problem when some users of my app reported it to me. For Android it continues to work normally and the problem only occurs on iOS.
Code snippet that calls the start
method:
const cameraPreviewOptions: CameraPreviewOptions = {
position: 'rear',
width: this.platformWidth,
height: this.platformHeight,
toBack: true,
rotateWhenOrientationChanged: false
};
await CameraPreview.start(cameraPreviewOptions);
some dependencies in my package.json: {
"@angular/core": "~10.0.0",
"@capacitor-community/camera-preview": "^1.0.6",
"@capacitor/android": "^2.4.3",
"@capacitor/core": "2.4.3",
"@capacitor/ios": "^2.4.3",
"@ionic/angular": "^5.0.0"
}
Issue Analytics
- State:
- Created a year ago
- Comments:13 (5 by maintainers)
@sertal70 @IgorSamer I can’t remember exactly what it was, but with iOS 15 there was view that was behaving differently or needed to be targeted to force the transparency.
In Plugin.swift -> start () try this:
self.webView?.backgroundColor = UIColor.clear self.webView?.isOpaque = false self.webView?.scrollView.backgroundColor = UIColor.clear self.webView?.scrollView.isOpaque = false
And in the stop() try this:
self.webView?.backgroundColor = self.viewColor ?? UIColor.white self.webView?.isOpaque = true
I’ve performed a set of tests to get some additional informations of this issue, here are my results. (All test have been done on iPhone XR with iOS 15.5)
Test 1
Original camera-preview plugin demo project: issue present
Test 2
Modified camera-preview plugin demo project with version 3 of Capacitor and plugin: issue present
Test 3
Original cordova-camera-preview demo project: issue not present
Test 4
Modified Capacitor camera-preview plugin demo project to use Cordova camera-preview plugin instead of Capacitor camera-preview plugin: issue not present
Definitely it seems an issue with the plugin, both in version 2 and 3. I tried to compare the iOS code of both plugins but I’m not an expert in iOS programming so I were unable to detect any differences between the two.