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
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 aasyncmethod, the code after awaiting this API call would not be executed.In the above snippet, when the
OnSensorRequestedmethod 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,
OnCameraRequestedworks as expected.Reproducible on iOS 16 & 17, using both .net 7.0.96 and 8.0.0 rc.2
Steps to Reproduce
Request Sensorbutton, accept the permission request.Request Sensorbutton againFor comparison, press the
Request CameraorRequest Locationbutton, 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