Skip to content

Commit

Permalink
set result after cleanup of locationmanager xamarin#1489
Browse files Browse the repository at this point in the history
On IOS if you like to request LocationAlways you have to request locationWhenInUse first. This means in an average implementation one would have to consecutive call
await Permissions.RequestAsync<Permissions.LocationWhenInUse>();  
Permissions.RequestAsync<Permissions.LocationAlways>();  
Both use the static LocationManager instance.
Since RequestAsync<Permissions.LocationWhenInUse>() sets the result of the task completition source before cleaning up its locationManager there is a race condition where RequestAsync<Permission.LocationAlways>() already runs and thus this cleanup disposes the locationManager used by the second call. This will not always be the case but in my test around 50% of the time. Workaround wait 3-10 seconds in between the calls
  • Loading branch information
SiNeumann authored and jfversluis committed Apr 4, 2022
1 parent 7bb913f commit 7c15655
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,9 @@ void LocationAuthCallback(object sender, CLAuthorizationChangedEventArgs e)
}

del.AuthorizationStatusChanged -= LocationAuthCallback;
tcs.TrySetResult(GetLocationStatus(whenInUse));
locationManager?.Dispose();
locationManager = null;
tcs.TrySetResult(GetLocationStatus(whenInUse));
}
catch (Exception ex)
{
Expand Down

0 comments on commit 7c15655

Please sign in to comment.