[iOS] Replace CA1416 pragmas in Shell/Navigation renderers with proper OS version guards
- Dominant language
- C#
- Stars
- 23.3k
- Forks
- 2k
- Avg merge
- 1d 10h
- Merged PRs (30d)
- 306
Description
## Background
While shepherding Preview 5 darc updates through #35718 we hit 6 CA1416 errors against `net11.0-ios26.5` in 3 Compatibility renderer files. To unblock the dependency PR we suppressed them inline with `#pragma warning disable CA1416`. This issue tracks the proper fix.
## Locations to fix
All under `src/Controls/src/Core/Compatibility/Handlers/`:
| File | Line | API | Required OS |
|---|---|---|---|
| `Shell/iOS/ShellPageRendererTracker.cs` | ~462 | `new UIBarButtonItem(UIImage, UIMenu)` | iOS 14.0+ |
| `NavigationPage/iOS/NavigationRenderer.cs` | ~1700 | `UIGraphics.BeginImageContext(CGSize)` | **deprecated** iOS 17.0+ |
| `NavigationPage/iOS/NavigationRenderer.cs` | ~1705 | `UIGraphics.GetImageFromCurrentImageContext()` | **deprecated** iOS 17.0+ |
| `NavigationPage/iOS/NavigationRenderer.cs` | ~2074 | `new UIBarButtonItem(UIImage, UIMenu)` | iOS 14.0+ |
| `Shell/iOS/ShellSectionRenderer.cs` | ~686 | `UINavigationItem.BackAction` setter | iOS 16.0+ |
| `Shell/iOS/ShellSectionRenderer.cs` | ~686 | `UIAction.Create(UIActionHandler)` | iOS 14.0+ |
The project's iOS `SupportedOSPlatformVersion` is `13.0` (set in `Directory.Build.targets`), so each of these calls is unguarded on a target where the API isn't available.
## Suggested fixes
- **`UIBarButtonItem(UIImage, UIMenu)`** (iOS 14+): wrap in `if (OperatingSystem.IsIOSVersionAtLeast(14) || OperatingSystem.IsMacCatalystVersionAtLeast(14))` with a fallback `UIBarButtonItem` for iOS 13.
- **`UIGraphics.BeginImageContext` / `GetImageFromCurrentImageContext`** (deprecated iOS 17+): migrate `GetEmptyBackIndicatorImage` to the modern `UIGraphicsImageRenderer` (available iOS 10+, not deprecated).
- **`UINavigationItem.BackAction = UIAction.Create(...)`** (iOS 16+): wrap in `if (OperatingSystem.IsIOSVersionAtLeast(16))` with the legacy `BackBarButtonItem` approach as the fallback for iOS 13–15.
## Why they slipped past local cake
`dotnet cake` succeeded locally with 0 CA1416 errors against the same `net11.0-ios26.5` TFM and same `Microsoft.iOS.Sdk.net11.0_26.5/26.5.11546-net11-p5` pack. CI catches them because `.editorconfig` sets `dotnet_diagnostic.CA1416.severity = error` and the analyzer ran during the CI build. We didn't dig fully into why the local analyzer pass produced 0 hits — worth investigating as part of this fix so we don't ship CA1416 regressions again.
## Suppressions to remove
The pragmas added in PR #35718 (commit referencing this issue) — `grep -rn 'CA1416' src/Controls/src/Core/Compatibility/` will find them.
Contributor guide
Research direction
Start with Directory.Build.targets and the three renderer files under src/Controls/src/Core/Compatibility/Handlers/, then grep for CA1416 suppressions. Review the listed APIs and their iOS availability, implement the specified guards or UIGraphicsImageRenderer migration, and run the relevant iOS build with CA1416 enabled. Done means the pragmas are removed and CI reports no CA1416 errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp, ios
- Domain
- mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 68/100