-
Notifications
You must be signed in to change notification settings - Fork 1.9k
WinUI targets require location permissions set in manifest when asking for location #8842
Copy link
Copy link
Closed
Labels
area-essentialsEssentials: Device, Display, Connectivity, Secure Storage, Sensors, App InfoEssentials: Device, Display, Connectivity, Secure Storage, Sensors, App Infofixed-in-7.0.0-rc.2.6866Look for this fix in 7.0.0-rc.2.6866!Look for this fix in 7.0.0-rc.2.6866!partnerIssue or Request from a partner teamIssue or Request from a partner teamplatform/windowst/bugSomething isn't workingSomething isn't working
Milestone
Description
Description
When requesting location access on windows, the application incorrectly validates that you have locations enabled in the application manifest. WinUI 3 apps do not require this to be defined to get a location. In fact the option isn't even in the manifest designer like it was with UWP apps.
The bug seems to be here, and caused by a raw import of the older UWP code:
maui/src/Essentials/src/Permissions/Permissions.uwp.cs
Lines 132 to 144 in 117436b
| internal static async Task<PermissionStatus> RequestLocationPermissionAsync() | |
| { | |
| if (!MainThread.IsMainThread) | |
| throw new PermissionException("Permission request must be invoked on main thread."); | |
| var accessStatus = await Geolocator.RequestAccessAsync(); | |
| return accessStatus switch | |
| { | |
| GeolocationAccessStatus.Allowed => PermissionStatus.Granted, | |
| GeolocationAccessStatus.Unspecified => PermissionStatus.Unknown, | |
| _ => PermissionStatus.Denied, | |
| }; | |
| } |
Could likely just be changed to:
internal static Task<PermissionStatus> RequestLocationPermissionAsync() => Task.FromResult(PermissionStatus.Granted)
(looking over this entire file, it might be affecting most of those permissions)
Steps to Reproduce
- Create a new maui app
- Add this code:
await Microsoft.Maui.ApplicationModel.Permissions.RequestAsync<Microsoft.Maui.ApplicationModel.Permissions.LocationWhenInUse>(); - Run on windows.
Observe the following exception thrown:
Version with bug
6.0.408 (current)
Last version that worked well
Unknown/Other
Affected platforms
Windows
Affected platform versions
Windows 10 18362+
Did you find any workaround?
Don't call this on Windows, or create custom permission:
private class LocationWhenInUse: Microsoft.Maui.ApplicationModel.Permissions.BasePlatformPermission
{
internal static Task<PermissionStatus> RequestLocationPermissionAsync() => Task.FromResult(PermissionStatus.Granted);
}Relevant log output
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
area-essentialsEssentials: Device, Display, Connectivity, Secure Storage, Sensors, App InfoEssentials: Device, Display, Connectivity, Secure Storage, Sensors, App Infofixed-in-7.0.0-rc.2.6866Look for this fix in 7.0.0-rc.2.6866!Look for this fix in 7.0.0-rc.2.6866!partnerIssue or Request from a partner teamIssue or Request from a partner teamplatform/windowst/bugSomething isn't workingSomething isn't working
