sharee.bike-App/TINKLib/Services/Permissions/Plugin/Permissions.cs

60 lines
2.1 KiB
C#
Raw Normal View History

2021-11-07 19:42:59 +01:00
using System.Threading.Tasks;
namespace TINK.Services.Permissions.Plugin
{
using global::Plugin.Permissions;
public class Permissions : ILocationPermission
{
/// <summary> Checks the permission status.</summary>
public async Task<Status> CheckStatusAsync()
{
switch (await CrossPermissions.Current.CheckPermissionStatusAsync<LocationPermission>())
{
case global::Plugin.Permissions.Abstractions.PermissionStatus.Denied:
return Status.Denied;
case global::Plugin.Permissions.Abstractions.PermissionStatus.Granted:
return Status.Granted;
case global::Plugin.Permissions.Abstractions.PermissionStatus.Unknown:
return Status.Unknown;
default:
// Comprises
// - PermissionStatus.Disabled and
// - PermissionStatus.Restricted.
return Status.DeniedRequiresSettingsUI;
}
}
/// <summary> Requests location permission.</summary>
/// <returns>Permission status after request.</returns>
public async Task<Status> RequestAsync()
{
switch (await CrossPermissions.Current.RequestPermissionAsync<LocationPermission>())
{
case global::Plugin.Permissions.Abstractions.PermissionStatus.Denied:
return Status.Denied;
case global::Plugin.Permissions.Abstractions.PermissionStatus.Granted:
return Status.Granted;
case global::Plugin.Permissions.Abstractions.PermissionStatus.Unknown:
return Status.Unknown;
default:
// Comprises
// - PermissionStatus.Disabled and
// - PermissionStatus.Restricted.
return Status.DeniedRequiresSettingsUI;
}
}
/// <summary> Opens app settings dialog.</summary>
public bool OpenAppSettings()
=> CrossPermissions.Current.OpenAppSettings();
}
}