-
Notifications
You must be signed in to change notification settings - Fork 592
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
bug: [iOS] CameraPlugin.presentCameraPicker Crashes Application #1996
Comments
By process of trial and error of comparing my app with the Code Reproduction sample, I noticed a discrepancy in the format of My file contained an entry for
And scouring my git history for modifications to this line, I realized that sometime along the way, it was originally committed as this, but later changed to remove the
Re-adding the A very weird issue, with a somewhat unexplained resolution. Maybe Capacitor framework could add some error handling to the code path which opens the camera (or the code path that moves the application to the background) so that this exception is surfaced in a more helpful way. |
That top one should have been rejected by apple: Apple's UIBackgroundModes Docs Seems like it's crashing on the Apple side, but in a weird way. Do you have a project I can look at that has this crash? |
I'll put together a code reproduction project for you soon. Apple has been happily accepting our |
I am experiencing the same issue. I updated an app that had the Cordova camera plugin to Capacitor 5.7. When I launch the app for the first time and access the camera, after taking a photo, the app closes. I immediately reopen it, repeat the same process, and everything works without any issues. This only happens in an iOS environment, and I have tested it on different devices and iOS versions. |
I have been researching possible solutions, and I have found one. I have implemented this method.
public checkAndRequestCameraPermission = async (): Promise<boolean> => {
const { photos, camera } = await Camera.checkPermissions();
if (photos === 'granted' && camera === 'granted') {
return true;
}
const permissionsToRequest: CameraPermissionType[] = [];
if (photos !== 'granted') permissionsToRequest.push('photos');
if (camera !== 'granted') permissionsToRequest.push('camera');
if (permissionsToRequest.length > 0) {
const { photos: newPhotos, camera: newCamera } = await Camera.requestPermissions({
permissions: permissionsToRequest,
});
return newPhotos === 'granted' && newCamera === 'granted';
}
return false;
}; Previously, I used to call it before using the camera, and I would encounter the error. I have moved its invocation to the app.component of my Ionic/Angular project, and then navigate to the functionality, and it doesn't fail. I'm not sure if it's the optimal solution, but it has at least solved the problem for me. |
This issue needs more information before it can be addressed. Please see the Contributing Guide for how to create a Sample App. Thanks! |
It looks like this issue didn't get the information it needed, so I'll close it for now. If I made a mistake, sorry! I am just a bot. Have a great day! |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of the plugin, please create a new issue and ensure the template is fully filled out. |
Bug Report
Plugin(s)
Camera
Capacitor Version
I'm using Ionic AppFlow for iOS builds. Since I develop on a Windows machine, I can't install XCode locally
Platform(s)
Current Behavior
When calling
Camera.getPhoto()
from JavaScript, the application crashes before displaying the camera live viewThe application will not crash if
source
isCameraSource.Photos
.The application will crash if source is
CameraSource.Prompt
and the user selects Camera; however it will not crash if the user selects galleryWatching the real-time iOS device logs using
3uTools
(I'm developing on Windows, so I don't have access to Apple's walled-garden tools) shows a few interesting lines (this is not a complete log capture; I just filtered for interesting stuff):I modified
CAPLog.swift
(https://github.com/ionic-team/capacitor/blob/main/ios/Capacitor/Capacitor/CAPLog.swift) to write to the iOS system log so that I could insert my own log points.I modified
CameraPlugin.swift
to includeCAPLog
statements at various points in the execution chain. I also addeddo/catch
error handling to various places in the Swift file to attempt logging the uncaught exception.I determined that the app crash occurs sometime after the call to
bridge?.viewController?.present
incapacitor-plugins/camera/ios/Sources/CameraPlugin/CameraPlugin.swift
Line 487 in 2fe419b
The plugin seems to correctly request authorization - the permission request dialogs appear on the screen.
I have the necessary strings in my
Info.plist
file:NSCameraUsageDescription
NSMicrophoneUsageDescription
NSPhotoLibraryAddUsageDescription
NSPhotoLibraryUsageDescription
The crash happens every single time I attempt to open the camera. None of the
do/catch
error handlers actually catch an error.Expected Behavior
Calling
getPhoto
should not crash when opening the camera.Code Reproduction
Other Technical Details
Additional Context
Possibly related bugs:
unrecognized selector sent to instance
Related Apple Developer Documentation
The text was updated successfully, but these errors were encountered: