public static async Task <PermissionStatus> CheckPermissions(BasePermission permission) { var permissionStatus = await permission.CheckPermissionStatusAsync(); bool request = false; if (permissionStatus == PermissionStatus.Denied) { if (Device.RuntimePlatform == Device.iOS) { var title = $"{permission} Permission"; var question = $"To use this plugin the {permission} permission is required. Please go into Settings and turn on {permission} for the app."; var positive = "Settings"; var negative = "Maybe Later"; var task = Application.Current?.MainPage?.DisplayAlert(title, question, positive, negative); if (task == null) { return(permissionStatus); } var result = await task; if (result) { CrossPermissions.Current.OpenAppSettings(); } return(permissionStatus); } request = true; } if (request || permissionStatus != PermissionStatus.Granted) { permissionStatus = await permission.RequestPermissionAsync(); if (permissionStatus != PermissionStatus.Granted) { var title = $"{permission} Permission"; var question = $"To use the plugin the {permission} permission is required."; var positive = "Settings"; var negative = "Maybe Later"; var task = Application.Current?.MainPage?.DisplayAlert(title, question, positive, negative); if (task == null) { return(permissionStatus); } var result = await task; if (result) { CrossPermissions.Current.OpenAppSettings(); } return(permissionStatus); } } return(permissionStatus); }
public static async Task <PermissionStatus> CheckPermissions(BasePermission permission) { var permissionStatus = await permission.CheckPermissionStatusAsync(); bool request = false; if (permissionStatus == PermissionStatus.Denied) { if (Device.RuntimePlatform == Device.iOS) { // The following lines have been added // `permission.ToString()` Starts as "Plugin.Permissions.LocationPermission", trim to "LocationPermission" var permissionString = permission.ToString().Split('.')[2]; permissionString = permissionString.Substring(0, permissionString.Length - 10); // The above lines have been added // The following 4 lines have been edited var title = $"{permissionString} permissions required"; var question = $"Please open Settings and allow {permissionString}."; var positive = "Open Settings"; var negative = "Deny permission"; // The above 4 lines have been edited var task = Application.Current?.MainPage?.DisplayAlert(title, question, positive, negative); if (task == null) { return(permissionStatus); } var result = await task; if (result) { CrossPermissions.Current.OpenAppSettings(); } return(permissionStatus); } request = true; } if (request || permissionStatus != PermissionStatus.Granted) { permissionStatus = await permission.RequestPermissionAsync(); if (permissionStatus != PermissionStatus.Granted) { // The following lines have been added // `permission.ToString()` Starts as "Plugin.Permissions.LocationPermission", trim to "LocationPermission" var permissionString = permission.ToString().Split('.')[2]; permissionString = permissionString.Substring(0, permissionString.Length - 10); // The above lines have been added // The following 4 lines have been edited var title = $"{permissionString} permissions required"; var question = $"Please open Settings and allow {permissionString}."; var positive = "Open Settings"; var negative = "Deny permission"; // The above 4 lines have been edited var task = Application.Current?.MainPage?.DisplayAlert(title, question, positive, negative); if (task == null) { return(permissionStatus); } var result = await task; if (result) { CrossPermissions.Current.OpenAppSettings(); } return(permissionStatus); } } return(permissionStatus); }