Skip to content

Fix Permission CTD for packaged/unpackaged apps using CameraView#3157

Open
ne0rrmatrix wants to merge 3 commits intoCommunityToolkit:mainfrom
ne0rrmatrix:FixCamerPermissionsBug
Open

Fix Permission CTD for packaged/unpackaged apps using CameraView#3157
ne0rrmatrix wants to merge 3 commits intoCommunityToolkit:mainfrom
ne0rrmatrix:FixCamerPermissionsBug

Conversation

@ne0rrmatrix
Copy link
Member

@ne0rrmatrix ne0rrmatrix commented Mar 17, 2026

Description of Change

There is a bug in CameraView in sample app where it requests permission for microphone and camera in an unpackaged app. This will crash the sample app. An unpackaged app does not require permissions for either camera or microphone when not packaged.

This also fixes a bug where the method signature for a Command is incorrect which is crashing sample app.

Linked Issues

PR Checklist

Additional information

This is another packaged/unpackaged app issue that is related to permissions. Includes a second bug that needed to be fixed to test and prevent crashes.

Updated CameraViewPage to grant permissions automatically for
unpackaged apps, avoiding unnecessary prompts. Changed
CreateStopCameraPreviewCommand to use Command<CancellationToken>
for consistency with start command.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns the CameraView stop-preview command factory with the existing bindable property type, and updates the sample app’s permission flow to account for packaged vs. unpackaged app behavior.

Changes:

  • Fix CreateStopCameraPreviewCommand to return Command<CancellationToken> (matching StopCameraPreviewCommandProperty / StopCameraPreviewCommand).
  • Update the CameraView sample to request camera/mic permissions only when the app is packaged, otherwise treat them as granted.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
src/CommunityToolkit.Maui.Camera/Views/CameraView.shared.cs Makes the stop-preview command default value creator return the correct generic Command<CancellationToken> type.
samples/CommunityToolkit.Maui.Sample/Pages/Views/CameraView/CameraViewPage.xaml.cs Adjusts runtime permission requests based on AppInfo.Current.PackagingModel to support unpackaged scenarios.

You can also share your feedback on Copilot code review. Take the survey.

@ne0rrmatrix
Copy link
Member Author

@VladislavAntonyuk can you take one more pass. I realized i excluded android,ios and mac catalyst. Fixed now.

var packagingModel = AppInfo.Current.PackagingModel;
PermissionStatus microphonePermissionsRequest;
PermissionStatus cameraPermissionsRequest;
if (packagingModel == AppPackagingModel.Packaged || OperatingSystem.IsAndroid() || OperatingSystem.IsIOS() || OperatingSystem.IsMacCatalyst())
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe better to use !Windows?

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated as you suggested. Good idea.

Refactored the logic for requesting camera and microphone permissions in OnAppearing. Instead of explicitly checking for Android, iOS, or MacCatalyst, permissions are now requested on all non-Windows platforms or when the app is packaged. This makes the condition more maintainable and future-proof.
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.

[BUG] CameraView StopCameraPreviewCommand is not working [BUG] CommunityToolkit sample app crashes opening CameraView page on Windows

3 participants