Optimize Apple camera session startup - #321
Merged
Merged
Conversation
Defer AVFoundation configuration until connection, configure the input and output together, and skip redundant mapper-triggered reconfiguration without moving startup out of the camera lifecycle.\n\nCo-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This was referenced Aug 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #319 by making Apple camera-session configuration connection-owned and idempotent instead of moving startup into a property mapper.
Root cause
Initial MAUI property mappings can call
UpdateCamera()several times. On iOS and Mac Catalyst, every call rebuilt the AVFoundation input graph and, once running, explicitly stopped and restarted the session. BecauseAVCaptureSession.StartRunning()is synchronous and expensive, these redundant cycles accumulated into the reported multi-second navigation delay.Compatibility risks in #320
PR #320 moves the first start from
CameraManager.Connect()toCameraBarcodeReaderViewHandler.MapVisibility(). That makes startup depend on a specific mapper invocation and can missCameraView, custom property mappers that omit visibility, async permission/lifecycle ordering, and Mac Catalyst (where the proposed__IOS__call is not compiled). It also leaves repeated session reconfiguration in place.Implementation
Connect()runs after camera permission is granted.BeginConfiguration()/CommitConfiguration()while running rather than explicit stop/start cycles.StartRunning()inCameraManager.Connect(), preserving both handlers and custom mapper behavior.Validation
dotnet test ZXing.Net.MAUI.Tests/ZXing.Net.MAUI.Tests.csproj -v:minimal(58 passed)dotnet build ZXing.Net.MAUI/ZXing.Net.MAUI.csproj -f net10.0-ios -v:minimaldotnet build ZXing.Net.MAUI/ZXing.Net.MAUI.csproj -f net10.0-maccatalyst -v:minimal