public async Task<GeofenceStatus> RequestState(GeofenceRegion region, CancellationToken? cancelToken) { var tcs = new TaskCompletionSource<GeofenceStatus>(); cancelToken?.Register(() => tcs.TrySetCanceled()); var handler = new EventHandler<CLRegionStateDeterminedEventArgs>((sender, args) => { var clregion = args.Region as CLCircularRegion; if (clregion?.Identifier.Equals(region.Identifier) ?? false) { var state = this.FromNative(args.State); tcs.TrySetResult(state); } }); try { this.locationManager.DidDetermineState += handler; var native = this.ToNative(region); this.locationManager.RequestState(native); return await tcs.Task; } finally { this.locationManager.DidDetermineState -= handler; } }
public void StartMonitoring(GeofenceRegion region) { //if !CLLocationManager.isMonitoringAvailableForClass(CLCircularRegion) { UIApplication.SharedApplication.InvokeOnMainThread(() => { var native = this.ToNative(region); this.locationManager.StartMonitoring(native); }); //this.locationManager.DesiredAccuracy //this.locationManager.StartMonitoring(native, this.DesiredAccuracy.TotalMeters); }
public void Remove(GeofenceRegion region) { this.MonitoredRegions.Remove(region); this.OnPropertyChanged(nameof(MonitoredRegions)); }
public GeofenceViewModel(GeofenceRegion region, ICommand removeCommand) { this.Region = region; this.Remove = removeCommand; }
public GeofenceStatusChangedEventArgs(GeofenceRegion region, GeofenceStatus status) { this.Region = region; this.Status = status; }
public void StopMonitoring(GeofenceRegion region) { var native = this.ToNative(region); this.locationManager.StopMonitoring(native); }
protected virtual CLCircularRegion ToNative(GeofenceRegion region) { return new CLCircularRegion( this.ToNative(region.Center), region.Radius.TotalMeters, region.Identifier ) { NotifyOnExit = true, NotifyOnEntry = true }; }