using Microsoft.JSInterop; using System.Threading.Tasks; namespace cwebplusApp.Shared.Services { public class PermissionsProvider { public IJSRuntime JSRuntime { get; set; } public bool IsGeoLocationAllowed { get; set; } public PermissionsProvider(IJSRuntime _jSRuntime) { this.JSRuntime = _jSRuntime; initialize(); } [JSInvokable] public void GeoLocationPermissionChanged(string geoLocationStatus) { IsGeoLocationAllowed = (geoLocationStatus.Equals("granted") || geoLocationStatus.Equals("prompt")) ? true : false; } private async void initialize() { await GeoLocationAllowed(); } private async Task GeoLocationAllowed() { string result = ""; var dotNetObjRef = DotNetObjectReference.Create(this); result = await JSRuntime.InvokeAsync("IsGeoLocationAllowed", dotNetObjRef); this.IsGeoLocationAllowed = result.Equals("granted") || result.Equals("prompt"); return IsGeoLocationAllowed; } } }