Skip to content

WinUI targets require location permissions set in manifest when asking for location #8842

@dotMorten

Description

@dotMorten

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:

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

  1. Create a new maui app
  2. Add this code: await Microsoft.Maui.ApplicationModel.Permissions.RequestAsync<Microsoft.Maui.ApplicationModel.Permissions.LocationWhenInUse>();
  3. Run on windows.
    Observe the following exception thrown:

image

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-essentialsEssentials: 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!partnerIssue or Request from a partner teamplatform/windowst/bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions