Skip to content
This repository has been archived by the owner on Apr 3, 2023. It is now read-only.

Exception with Xamarin.Essentials #127

Open
vd3d opened this issue Oct 28, 2018 · 1 comment
Open

Exception with Xamarin.Essentials #127

vd3d opened this issue Oct 28, 2018 · 1 comment

Comments

@vd3d
Copy link

vd3d commented Oct 28, 2018

Hi,

I try to use Xamarin.Essentials, and mainly the following code:

await CheckPermissions(Permission.LocationWhenInUse);
var request = new GeolocationRequest(GeolocationAccuracy.Best);
return await Geolocation.GetLocationAsync(request);

Before, I check the permissions with this method, no dialog appear and I got a "granted" permission.
The problem is that I got an exception:

Xamarin.Essentials.PermissionException: 'LocationWhenInUse was not granted.'

What is strange is that I got this exception in (UWP x86) but not in (UWP x64) !!!!

Here is my code:

static async private Task CheckPermissions(Permission permission)
        {
            try
            {
                var status = await CrossPermissions.Current.CheckPermissionStatusAsync(permission);
                if (status != PermissionStatus.Granted)
                {
                    if (await CrossPermissions.Current.ShouldShowRequestPermissionRationaleAsync(permission))
                    {
                        //await NavigationHelper.CurrentPage.DisplayAlert("Need location", "Gunna need that location", "OK");
                    }

                    var results = await CrossPermissions.Current.RequestPermissionsAsync(permission);
                    //Best practice to always check that the key exists
                    if (results.ContainsKey(permission))
                        status = results[permission];
                }

                if (status == PermissionStatus.Granted)
                {
                    //var results = await CrossGeolocator.Current.GetPositionAsync(10000);
                    //LabelGeolocation.Text = "Lat: " + results.Latitude + " Long: " + results.Longitude;
                }
                else if (status != PermissionStatus.Unknown)
                {
                    await NavigationHelper.CurrentPage.DisplayAlert("Location Denied", "Can not continue, try again.", "OK");
                }
            }
            catch (Exception ex)
            {

                //LabelGeolocation.Text = "Error: " + ex;
            }
        }
@mostafa901
Copy link

yep, same issue here... any advise?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants