mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2025-04-24 13:46:30 +02:00
Version 3.0.255
This commit is contained in:
parent
db9c288584
commit
5a26bf273b
1495 changed files with 159465 additions and 5060 deletions
80
TINKLib/Services/Permissions/Essentials/Permissions.cs
Normal file
80
TINKLib/Services/Permissions/Essentials/Permissions.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
using System.Threading.Tasks;
|
||||
using Xamarin.Essentials;
|
||||
|
||||
namespace TINK.Services.Permissions.Essentials
|
||||
{
|
||||
using XamPermission = Xamarin.Essentials.Permissions;
|
||||
using XamPermissionStatus = PermissionStatus;
|
||||
|
||||
public class Permissions : ILocationPermission
|
||||
{
|
||||
/// <summary> Checks the permission status.</summary>
|
||||
/// <returns>Current permission status.</returns>
|
||||
public async Task<Status> CheckStatusAsync()
|
||||
{
|
||||
var status = await XamPermission.CheckStatusAsync<XamPermission.LocationWhenInUse>();
|
||||
if (status == XamPermissionStatus.Granted)
|
||||
{
|
||||
return Status.Granted;
|
||||
}
|
||||
|
||||
if (status == XamPermissionStatus.Denied
|
||||
&& DeviceInfo.Platform == DevicePlatform.iOS)
|
||||
{
|
||||
// Prompt the user to turn on in settings
|
||||
// On iOS once a permission has been denied it may not be requested again from the application
|
||||
return Status.DeniedRequiresSettingsUI;
|
||||
}
|
||||
|
||||
if (XamPermission.ShouldShowRationale<XamPermission.LocationWhenInUse>())
|
||||
{
|
||||
// Prompt the user with additional information as to why the permission is needed
|
||||
return Status.Denied;
|
||||
}
|
||||
|
||||
switch (status)
|
||||
{
|
||||
case XamPermissionStatus.Unknown:
|
||||
case XamPermissionStatus.Denied: // Map Denied to unknown because "denied means user did not allow access to location".
|
||||
return Status.Unknown;
|
||||
|
||||
default:
|
||||
// Comprises:
|
||||
// - XamPermissionStatus.Restricted:
|
||||
// - XamPermissionStatus.Disabled
|
||||
// Perission XamPermissionStatus.Granted is handled above.
|
||||
return Status.DeniedRequiresSettingsUI;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Requests location permission.</summary>
|
||||
/// <returns>Permission status after request.</returns>
|
||||
public async Task<Status> RequestAsync()
|
||||
{
|
||||
switch (await XamPermission.RequestAsync<XamPermission.LocationWhenInUse>())
|
||||
{
|
||||
case XamPermissionStatus.Unknown:
|
||||
return Status.Unknown;
|
||||
|
||||
case XamPermissionStatus.Denied:
|
||||
return Status.Denied;
|
||||
|
||||
case XamPermissionStatus.Granted:
|
||||
return Status.Granted;
|
||||
|
||||
default:
|
||||
// Comprises:
|
||||
// - XamPermissionStatus.Restricted:
|
||||
// - XamPermissionStatus.Disabled
|
||||
return Status.DeniedRequiresSettingsUI;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Opens app settings dialog.</summary>
|
||||
public bool OpenAppSettings()
|
||||
{
|
||||
AppInfo.ShowSettingsUI();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue