Sometimes I wish APIs would work the way you expect them to. Yesterday, I spent a couple of hours trying to figure out why the following code just hangs.
var loc = new Geolocator(this) { DesiredAccuracy = 50 };
var pos = await loc.GetPositionAsync(timeout: 4000);
The await-call never returns. From the look of it, I would expect it to return after 4 seconds or at least throw an exception.
So I posted a question on the Xamarin Android forum and as usual got some great feedback. The answer was simple, restart your device. There seems to be a bug deeper down in android that is well-known.
This is terrible, that means that I cannot rely on the async call to ever return. I guess the only way out of this is to wrap this in an API of my own that handles these hangs and informs the user to restart their device.
Sometimes I miss iOS... :)
Oh, and here's the original question on the forum.
No comments:
Post a Comment