Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 58056

iOS Current Location Access

$
0
0

Hi guys,

Requirement:
--------------

I have a requirement in my app where the user clicks check-in, the app gets the current user location and saves the check-in time. App should proceed to save the details only after the user allows to access the current location.

Problem:
----------

When we use location services in an application, we receive an IOS alert saying the application is trying to use the current location -- Allow/Don't Allow.

I want to force the user to select Allow application to use the current location to proceed further. Currently what is happening is irrespective of user selecting Allow/Don't Allow, it proceeds to save the check-in time.

I have tried the following

Native iOS:

    public bool IsGeolocationEnabled
    {
        get {

            return (CLLocationManager.Status >= CLAuthorizationStatus.AuthorizedAlways && CLLocationManager.LocationServicesEnabled);
         }
    }

Usage:

if (!_Geolocator.IsGeolocationEnabled)
{

                this.ShowMessage("Location Service Disabled", Device.OS == TargetPlatform.Android ? Constants.LocationErrorMessageDroid : Device.OS == TargetPlatform.iOS ? Constants.LocationErrorMessageiOS : Constants.LocationErrorMessageWin);
                return false;
            }
            this.ScheduleVM.IsBusy = true;
            this.ScheduleVM.LoadingMessage = "Getting Current Location...";

            await this._Geolocator.GetPositionAsync(20000)
                    .ContinueWith(t =>
                    {
                        IsBusy = false;
                        if (t.IsFaulted)
                        {

                            Debug.Write("Fault");
                        }
                        else if (t.IsCanceled)
                        {
                            Debug.Write("Canceled");
                        }
                        else
                        {
                            ScheduleVM.CurrentLocation = new LatLongValue();
                            ScheduleVM.CurrentLocation = new LatLongValue
                            {
                                Latitude = t.Result.Latitude,
                                Longitude = t.Result.Longitude
                            };
                        }
                    });

Viewing all articles
Browse latest Browse all 58056

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>