예제 #1
0
        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);
        }
예제 #2
0
        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);
        }
예제 #3
0
        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());
        }
예제 #4
0
        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);
            }
        }
예제 #5
0
        public override async Task StopMonitoring(GeofenceRegion region)
        {
            await this.Repository.Remove(region.Identifier);

            this.locationManager.StopMonitoring(region.ToNative());
        }