Hello everyone,
I have the following code which runs nicely on iOS and Android.
Although in iOS I would like to wait until the user hits either Allow or Don't allow
location before firing the code.
How could I implement this, I am having trouble finding documentation about this.
#if __ANDROID__
var locator = new Geolocator (Forms.Context) { DesiredAccuracy = 50 };
#endif
#if __IOS__
var locator = new Geolocator { DesiredAccuracy = 50 };
#endif
if (!locator.IsGeolocationAvailable) {
Console.WriteLine ("Unavaible on device");
sfPosition = new SFPosition (0, 0, "Unavaible on device");
} else if (!locator.IsGeolocationEnabled) {
Console.WriteLine ("Disabled on device");
sfPosition = new SFPosition (0, 0, "Disabled on device");
} else {
Position position = await locator.GetPositionAsync (timeout: 10000);
if (position == null) {
sfPosition = new SFPosition (0, 0, "Failed on device");
} else {
sfPosition = new SFPosition(position.Latitude, position.Longitude, "Ok");
}
}
My first guess is making a while loop that lasts 10 seconds (same as the timeout) as long as locator.IsGeolocationEnabled
is false.
But this will make the App wait 10 seconds if the user declined it before which is not what I want.
Any help or pointers are greatly appreciated !
Thanks in advance