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

Crash on iOS when camera permissions are denied #98

Open
nzohrab opened this issue Oct 3, 2024 · 3 comments
Open

Crash on iOS when camera permissions are denied #98

nzohrab opened this issue Oct 3, 2024 · 3 comments

Comments

@nzohrab
Copy link

nzohrab commented Oct 3, 2024

Hello there,

I've come across an issue which crashes the app under iOS. I've tested on the latest version 1.5.8, and as far back as 1.3.1 and the issue is there too.

To recreate this, in BarcodeScanning.Test, click the 'Open ScanPage' button.
Then when asked for camera permissions, click 'Don't Allow'.
Then click the '<' back button.
Finally, click 'Open ScanPage' again, and the app crashes, giving this error:
System.Exception: 'Could not initialize an instance of the type 'AVFoundation.AVCaptureDeviceInput': the native 'initWithDevice:error:' method returned nil. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.'

On this line of code:
_captureInput = new AVCaptureDeviceInput(_captureDevice, out _);

In MaciOS/CameraManager.cs

In short it seems like the crash happens when permissions have been denied and the user lands on a page with the CameraView on it.

For reference, I'm running iOS version 17.5.1 on an IPhone 12. We've had users telling us they're having this issue with our app too.

I'm not sure about a workaround at the moment, but I'm going to try only injecting the CameraView into the page if camera permissions are granted and see how that goes.

@nzohrab
Copy link
Author

nzohrab commented Oct 3, 2024

Just confirming the workaround mentioned above does work for our app!

@afriscic
Copy link
Owner

afriscic commented Oct 3, 2024

Hello.

Yes, on iOS if the permission is denied once you have to handle the result and prompt your user to manually grant the permission in settings.
See here: https://learn.microsoft.com/en-us/dotnet/maui/platform-integration/appmodel/permissions?view=net-maui-8.0&tabs=macios#platform-differences

@breyed
Copy link

breyed commented Oct 22, 2024

To avoid coupling the permissions into the client app, it would be good to add a method alongside Methods.AskForRequiredPermissionAsync called HasRequiredPermissionAsync.

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

No branches or pull requests

3 participants