Skip to content

Make ScanFromPhotosAsync iOS-only - #1

Merged
Bohirjon merged 1 commit into
mainfrom
ios-only-scan-from-photos
Sep 7, 2026
Merged

Bohirjon merged 1 commit into
mainfrom
ios-only-scan-from-photos

Conversation

@Bohirjon

@Bohirjon Bohirjon commented Sep 7, 2026

Copy link
Copy Markdown
Owner

What

ScanFromPhotosAsync is now iOS-only: annotated [SupportedOSPlatform("ios")] and throwing NotSupportedException on Android. Android's ML Kit scanner always offers its import-from-gallery button.

Why

On Android the method opened the camera scanner, not the gallery — ML Kit cannot start in the gallery. A method named "scan from photos" that opens a camera is misleading, and the intermediate attempts to paper over it (renaming it, adding an IsScanFromPhotosSupported flag, an AllowGalleryImport option) each left the confusion somewhere in the public API.

How

The platform annotation turns an unguarded call into a CA1416 compile-time warning instead of a runtime surprise; OperatingSystem.IsIOS() is the guard consumers use, so no capability property is needed. XML docs on both methods now state the per-platform behaviour, and the Android exception message names the alternative.

Testing

dotnet build on the solution: 0 errors, no CS/CA warnings, both net10.0-android and net10.0-ios. Confirmed CA1416 actually fires by temporarily dropping the sample's guard and rebuilding. Not redeployed to hardware for this change — the scan flows themselves were device-tested earlier, but the Android gallery-button default and the new throw have not been exercised on a device.

Notes for reviewers

Breaking for anyone on 0.1.0 calling ScanFromPhotosAsync on Android; recorded under the unreleased 0.2.0 in CHANGELOG. Also folded in three README fixes found while editing those sections: the usage snippet declared pages three times (wouldn't compile if pasted), the platform table's PageLimit row was stale, and the text claimed ScanAsync throws NotSupportedException on all platforms when only Android does.

On Android the method opened ML Kit's camera scanner rather than the
gallery, because ML Kit cannot start in the gallery. Mark it
[SupportedOSPlatform("ios")] so an unguarded call is a CA1416 warning,
and throw NotSupportedException on Android with the alternative in the
message. Android's scanner now always offers its import-from-gallery
button, which is the platform's real gallery route.

Document the per-platform behaviour on both methods so IntelliSense
answers it without the README.
@coderabbitai

coderabbitai Bot commented Sep 7, 2026 •

Copy link
Copy Markdown

Important

  • Pull request is closed - (🔄 Check again to try again)

This repository does not receive automatic reviews because it has fewer than 10 stars.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Team

Run ID: 836c8052-9e6e-40e9-aeca-2b7a7ed7c0e1


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@Bohirjon
Bohirjon merged commit 8434859 into main Sep 7, 2026
1 check passed
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.

1 participant