GH-373: Permissions Must Be Invoked on MainThread else Throw Exception (#487)
* Throw permission exception if not on main thread when we need to request. * Add tests for not main thread permissions
This commit is contained in:
Родитель
ca6bd84895
Коммит
fc17df9e61
|
@ -37,5 +37,14 @@ namespace DeviceTests
|
|||
|
||||
Assert.Equal(expectedStatus, status);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public async Task Request_NotMainThread()
|
||||
{
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
await Assert.ThrowsAsync<PermissionException>(() => Permissions.RequestAsync(PermissionType.LocationWhenInUse));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,8 +12,13 @@ namespace Xamarin.Essentials
|
|||
internal static Task<PermissionStatus> CheckStatusAsync(PermissionType permission) =>
|
||||
PlatformCheckStatusAsync(permission);
|
||||
|
||||
internal static Task<PermissionStatus> RequestAsync(PermissionType permission) =>
|
||||
PlatformRequestAsync(permission);
|
||||
internal static Task<PermissionStatus> RequestAsync(PermissionType permission)
|
||||
{
|
||||
if (!MainThread.IsMainThread)
|
||||
throw new PermissionException("Permission request must be invoked on main thread.");
|
||||
|
||||
return PlatformRequestAsync(permission);
|
||||
}
|
||||
|
||||
internal static async Task RequireAsync(PermissionType permission)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче