public override async Task StartMonitoring(GeofenceRegion region) { var access = await this.RequestAccess(); access.Assert(); var native = region.ToNative(); var tcs = new TaskCompletionSource <object>(); UIApplication.SharedApplication.BeginInvokeOnMainThread(async() => { try { this.locationManager.StartMonitoring(native); tcs.SetResult(null); } catch (Exception ex) { this.locationManager.StopMonitoring(native); tcs.SetException(ex); } }); await tcs.Task.ConfigureAwait(false); await this.Repository.Set(region.Identifier, region); }
public override async Task <GeofenceState> RequestState(GeofenceRegion region, CancellationToken cancelToken = default) { var task = this.gdelegate .WhenStateDetermined() .Where(x => region.Equals(x)) .Select(x => x.Status) .Timeout(TimeSpan.FromSeconds(20)) .ToTask(cancelToken); this.locationManager.RequestState(region.ToNative()); var result = await task.ConfigureAwait(false); return(result); }
public override async Task <GeofenceState> RequestState(GeofenceRegion region, CancellationToken cancelToken = default) { var task = Observable .FromEventPattern <CLRegionStateDeterminedEventArgs>( x => this.gdelegate.DeterminedState += x, x => this.gdelegate.DeterminedState -= x ) .Timeout(TimeSpan.FromSeconds(20)) .Take(1) .Select(x => x.EventArgs) .Where(x => x.Region is CLRegion native && native.Identifier.Equals(region.Identifier)) .ToTask(cancelToken); this.locationManager.RequestState(region.ToNative()); var args = await task; return(args.State.FromNative()); }
public override async Task <GeofenceState> RequestState(GeofenceRegion region, CancellationToken cancelToken = default) { var task = this.gdelegate .WhenStateDetermined() .Where(x => region.Equals(x)) .Select(x => x.Status) .Timeout(TimeSpan.FromSeconds(20)) .ToTask(cancelToken); this.locationManager.RequestState(region.ToNative()); try { var result = await task.ConfigureAwait(false); return(result); } catch (TimeoutException ex) { throw new TimeoutException("Could not retrieve latest GPS coordinates to be able to determine geofence current state", ex); } }
public override async Task StopMonitoring(GeofenceRegion region) { await this.Repository.Remove(region.Identifier); this.locationManager.StopMonitoring(region.ToNative()); }