KEMBAR78
iOS: Permissions.RequestAsync is getting main thread warnings · Issue #29172 · dotnet/maui · GitHub
Skip to content

iOS: Permissions.RequestAsync is getting main thread warnings #29172

@rolfbjarne

Description

@rolfbjarne

From @mmiller-d8 on Mon, 21 Apr 2025 20:13:00 GMT

Type: Bug

This is on iOS.

When calling Permissions.RequestAsync<Premissions.LocationWhenInUse> it prints out three instances of a warning saying that performance may be impacted when running on the main thread. Of course, you must call RequestAsync on the main thread because it can show a dialog. If you don't, an exception is thrown.

I have not tried to look at the source, but it looks like that method is doing other stuff that shouldn't be done on the UI thread. I might also assume that it is just running on whatever thread it's called from, especially since it doesn't work if you don't explicitly call it on the main thread.

My Maui extension is out of date because, well, I don't have a full day to update it. Every time I end up having to upgrade other things.

Here's the code I'm calling:

Debug.WriteLine($"Is MainThread: {MainThread.IsMainThread}");
 PermissionStatus status = await Permissions.CheckStatusAsync<Permissions.LocationWhenInUse>();

 await MainThread.InvokeOnMainThreadAsync(async () => {
        Debug.WriteLine("Requesting access");
        if (status != PermissionStatus.Granted)
            status = await Permissions.RequestAsync<Permissions.LocationWhenInUse>();
       Debug.WriteLine("Requested access");
 });

And here is the debug output:

Is MainThread: False
Checking status
Requesting access
2025-04-21 15:18:19.987018-0500 D8.Mobile[61036:115145116] [CoreLocation] __delegate_identifier__:Performance Diagnostics__:::____message__: This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the `-locationManagerDidChangeAuthorization:` callback and checking `authorizationStatus` first.

2025-04-21 15:18:19.988760-0500 D8.Mobile[61036:115145116] [CoreLocation] __delegate_identifier__:Performance Diagnostics__:::____message__: This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the `-locationManagerDidChangeAuthorization:` callback and checking `authorizationStatus` first.

2025-04-21 15:18:19.992727-0500 D8.Mobile[61036:115145116] [CoreLocation] __delegate_identifier__:Performance Diagnostics__:::____message__: This method can cause UI unresponsiveness if invoked on the main thread. Instead, consider waiting for the `-locationManagerDidChangeAuthorization:` callback and checking `authorizationStatus` first.

Requested access

Extension version: 1.8.9
VS Code version: Code 1.99.2 (4949701c880d4bdb949e3c0e6b400288da7f474b, 2025-04-10T01:21:25.295Z)
OS version: Darwin arm64 24.3.0
Modes:

System Info
Item Value
CPUs Apple M3 Max (14 x 2400)
GPU Status 2d_canvas: enabled
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: disabled_off
Load (avg) 5, 5, 5
Memory (System) 96.00GB (0.43GB free)
Process Argv --crash-reporter-id 1618046c-b005-4c1a-89ae-cb627902572c
Screen Reader no
VM 0%
A/B Experiments
vsliv368cf:30146710
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
pythonvspyt551:31249599
vscod805:30301674
binariesv615:30325510
c4g48928:30535728
azure-dev_surveyone:30548225
a9j8j154:30646983
962ge761:30959799
2e7ec940:31000449
pythontbext0:30879054
cppperfnew:31000557
dwnewjupytercf:31046870
pythonrstrctxt:31112756
nativeloc1:31192215
5fd0e150:31155592
dwcopilot:31170013
6074i472:31201624
dwoutputs:31242946
customenabled:31248079
9064b325:31222308
copilot_t_ci:31222730
e5gg6876:31282496
cp15370_t:31280197
pythoneinst12:31262605
bgtreat:31268568
4gafe986:31271826
31787653:31262186
3e8i5726:31271747
996jf627:31283433
usemplatestapi:31280917
763bd867:31283000
747dc170:31275177
aj496949:31278748
aj953862:31281341

Copied from original issue microsoft/vscode-dotnettools#1950

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions