Skip to content

[iOS] Permissions.RequestAsync<Permissions.Sensors> does not return a value on iOS16+ #18669

@zhitaop

Description

@zhitaop

Description

The Maui Permissions.RequestAsync<Permissions.Sensors> API does not return a value on iOS 16 or above, when invoked for the first time and user grants the permission. When called in a async method, the code after awaiting this API call would not be executed.

<VerticalStackLayout>
        <Button
            Text="Request Sensor"
            Clicked="OnSensorRequested" />
        <Button
            Text="Request Camera"
            Clicked="OnCameraRequested" />
        <Label
            x:Name="debugText"/>
</VerticalStackLayout>
int sensorCount, cameraCount = 0;

private async void OnSensorRequested(object sender, EventArgs e)
{
    sensorCount++;
    var status = await Permissions.RequestAsync<Permissions.Sensors>();
    debugText.Text += $"Sensor Permission Request result: {status}, click counter {sensorCount}\n";
}

private async void OnCameraRequested(object sender, EventArgs e)
{
    cameraCount++;
    var status = await Permissions.RequestAsync<Permissions.Camera>();
    debugText.Text += $"Camera Permission Request result: {status}, click counter {cameraCount}\n";
}

In the above snippet, when the OnSensorRequested method is invoked for the first time after fresh install of the app, and user grants the permission, the debug text would not be updated.

Subsequent call of the method works as expected. If user denies the permission in the first call, it also works as expected (text is updated).

For comparison, OnCameraRequested works as expected.

Reproducible on iOS 16 & 17, using both .net 7.0.96 and 8.0.0 rc.2

Steps to Reproduce

  • Run the reproduction project on a iOS 16+ device.
  • Press the Request Sensor button, accept the permission request.
  • Observe that nothing is logged to screen
  • Press the Request Sensor button again
  • Text is logged to screen with counter 2

For comparison, press the Request Camera or Request Location button, observe that text is logged to the screen immediately after permission is granted.

Link to public reproduction project repository

https://github.com/zhitaop/MauiSensorPermissionBugiOS16

Version with bug

7.0.96

Is this a regression from previous behavior?

Not sure, did not test other versions

Last version that worked well

Unknown/Other

Affected platforms

iOS

Affected platform versions

iOS16, iOS17

Did you find any workaround?

No response

Relevant log output

No response

Metadata

Metadata

Assignees

Labels

area-essentialsEssentials: Device, Display, Connectivity, Secure Storage, Sensors, App Infogood first issueGood for newcomerspartner/syncfusionIssues / PR's with Syncfusion collaborationplatform/iost/bugSomething isn't workingversion/ios-16

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions