Skip to content

Fix UIKit thread error in AppInfo and DeviceDisplay platform handlers#35

Merged
Redth merged 1 commit intomainfrom
fix/platform-uikit-thread
Mar 11, 2026
Merged

Fix UIKit thread error in AppInfo and DeviceDisplay platform handlers#35
Redth merged 1 commit intomainfrom
fix/platform-uikit-thread

Conversation

@Redth
Copy link
Copy Markdown
Owner

@Redth Redth commented Mar 11, 2026

Summary

Fixes #34

/api/platform/app-info and /api/platform/device-display fail on iOS with:

UIKit Consistency error: you are calling a UIKit method that can only be invoked from the UI thread.

Changes

Wrap both handlers in MainThread.InvokeOnMainThreadAsync() to dispatch UIKit-dependent API calls to the main thread:

  • HandlePlatformAppInfoAppInfo.Current.RequestedTheme and RequestedLayoutDirection require UIKit
  • HandlePlatformDeviceDisplayDeviceDisplay.MainDisplayInfo requires UIKit

Other platform handlers (DeviceInfo, Battery, Connectivity, VersionTracking) work fine from background threads and don't need this change.

Testing

  • Verified the fix compiles against MauiDevFlow.Agent.Core
  • The bug was discovered while building the Platform Features tab in MAUI Sherpa's MauiDevFlow inspector

AppInfo.Current (RequestedTheme, RequestedLayoutDirection) and
DeviceDisplay.MainDisplayInfo access UIKit APIs that must be called
on the main thread. The HTTP server handlers run on a background thread,
causing 'UIKit Consistency error' on iOS.

Wrap both handlers in MainThread.InvokeOnMainThreadAsync() to dispatch
to the UI thread before accessing these APIs.

Fixes #34

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@Redth Redth merged commit 30d8012 into main Mar 11, 2026
2 checks passed
@Redth Redth deleted the fix/platform-uikit-thread branch March 11, 2026 17:31
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.

Platform endpoints: AppInfo and DeviceDisplay throw UIKit thread error

1 participant