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
};
}
});