Forum Cross Platform with Xamarin

CrossPermissions Current RequestPermissionsAsync()

When asking for the location if the permission is not yet grated I get the popup as I should.
But when the system popup comes up, my busy spinner turns off...as I would expect it would...however.....when I Grant the permissions the busy spinner comes back, basically just a flash, and the method completes....I can count to about 5 and my field updates with the location. If the permission is already granted...I get the busy spinner the entire time and the field is updated when the spinner is done. I am absolutely baffled as to why when granting the permission the method completes and 5 seconds later the value actually shows up.

Best Answer

  • sisaackssisaacks Member ✭✭✭
    Accepted Answer

    Okay I figured it out using stack trace. When the system calls the permissions popup xamarin calls OnPageDisappearing() where I was setting IsBusy to True and False which was affecting my other method. I had no idea calling a popup would make the window disappear.

Answers

  • sisaackssisaacks Member ✭✭✭

    Okay what is strange is that if the permission is already granted....i have a busy spinner the entire time...if it is not granted the following call causes the busy spinner to stop.
    status = await CrossPermissions.Current.RequestPermissionAsync();

    So I followed the line above with
    await Device.InvokeOnMainThreadAsync(() => IsBusy = true);

    Which kicked off IsBusy to true but as soon as I call the next method....IsBusy is again set to False somehow
    GeolocationRequest request = new GeolocationRequest(GeolocationAccuracy.Best, TimeSpan.FromSeconds(15));
    location = await Geolocation.GetLocationAsync(request);

    I am absolutely baffled as to what is going on. Its like the device is causing IsBusy to go to false

  • sisaackssisaacks Member ✭✭✭

    I am guessing it must be something with granting permissions and assigning the values? Because if permissions are already enabled this works flawless...but if I have to enable permissions then the busy spinner disappears and there is quite a delay....and the value finally loads.
    I even put a tasks delay with a busy spinner and that never happened either.

  • sisaackssisaacks Member ✭✭✭

    Its almost like the device sleeps the GPS module until an app requests location, then wakes it up to get a satellite lock
    I am not entirely sure how to get this to work correctly

  • sisaackssisaacks Member ✭✭✭

    Here is the methods. What I do not get...is if I have to request the permission......even if I set IsBusy to true.....for some reason it will get set to false. Has anyone dealt with this before????

    if(await CheckLocationServices(shouldShowCheckBox:false, overrideUser:true))
    {
    Plugin.Permissions.Abstractions.PermissionStatus permissionStatus = await PermissionCheck(Permission.Location);

                    if (permissionStatus == Plugin.Permissions.Abstractions.PermissionStatus.Granted)
                    {
                        Location location = await LocationUtility.GetCurrentLocation();
    
                        if (location != null)
                        {
                            await DoWork();
                            await DoMoreWork();
                        }
                    }
                }
    

    public async Task PermissionCheck(Permission permission)
    {
    PermissionStatus status = PermissionStatus.Unknown;

            switch (permission)
            {
                case Permission.Location:
                    status = await CrossPermissions.Current.CheckPermissionStatusAsync<LocationPermission>();
                    break;
    
                case Permission.Storage:
                    status = await CrossPermissions.Current.CheckPermissionStatusAsync<StoragePermission>();
                    break;
            }
    
            if (status != PermissionStatus.Granted)
            {
                switch (permission)
                {
                    case Permission.Location:
                        status = await CrossPermissions.Current.RequestPermissionAsync<LocationPermission>();
                        break;
    
                    case Permission.Storage:
                        status = await CrossPermissions.Current.RequestPermissionAsync<StoragePermission>();
                        break;
                }
            }
    
            return status;
        }
    
  • sisaackssisaacks Member ✭✭✭

    Also this is an android phone....I think this may have something to do with the override method required in the MainActivity
    Anyway...hoping someone has some info....

  • sisaackssisaacks Member ✭✭✭
    Accepted Answer

    Okay I figured it out using stack trace. When the system calls the permissions popup xamarin calls OnPageDisappearing() where I was setting IsBusy to True and False which was affecting my other method. I had no idea calling a popup would make the window disappear.

Sign In or Register to comment.