Esempio n. 1
0
        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;
            }
        }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 public void Remove(GeofenceRegion region)
 {
     this.MonitoredRegions.Remove(region);
     this.OnPropertyChanged(nameof(MonitoredRegions));
 }
Esempio n. 4
0
 public GeofenceViewModel(GeofenceRegion region, ICommand removeCommand)
 {
     this.Region = region;
     this.Remove = removeCommand;
 }
 public GeofenceStatusChangedEventArgs(GeofenceRegion region, GeofenceStatus status)
 {
     this.Region = region;
     this.Status = status;
 }
Esempio n. 6
0
 public void StopMonitoring(GeofenceRegion region)
 {
     var native = this.ToNative(region);
     this.locationManager.StopMonitoring(native);
 }
Esempio n. 7
0
 protected virtual CLCircularRegion ToNative(GeofenceRegion region)
 {
     return new CLCircularRegion(
         this.ToNative(region.Center),
         region.Radius.TotalMeters,
         region.Identifier
     )
     {
         NotifyOnExit = true,
         NotifyOnEntry = true
     };
 }