Exemple #1
0
        public override async Task <AccessState> RequestAccess(bool monitoring)
        {
            if (!CLLocationManager.LocationServicesEnabled)
            {
                return(AccessState.Disabled);
            }

            if (!CLLocationManager.IsMonitoringAvailable(typeof(CLCircularRegion)))
            {
                return(AccessState.NotSupported);
            }

            var result = CLLocationManager.Status;

            if (result == CLAuthorizationStatus.NotDetermined)
            {
                var tcs     = new TaskCompletionSource <CLAuthorizationStatus>();
                var handler = new EventHandler <CLAuthorizationStatus>((sender, status) => tcs.TrySetResult(status));
                this.gdelegate.AuthStatusChanged += handler;

                if (monitoring)
                {
                    this.manager.RequestAlwaysAuthorization();
                }
                else
                {
                    this.manager.RequestWhenInUseAuthorization();
                }

                result = await tcs.Task;
                this.gdelegate.AuthStatusChanged -= handler;
            }
            return(result.FromNative(monitoring));
        }
Exemple #2
0
        private GeofenceMonitor()
        {
#if __UNIFIED__
            _locationManager = new CLLocationManager();
            _locationManager.DesiredAccuracy       = CLLocation.AccuracyBest;
            _locationManager.AuthorizationChanged += _locationManager_AuthorizationChanged;
            _locationManager.LocationsUpdated     += _locationManager_LocationsUpdated;
#if __IOS__
            _locationManager.AllowsBackgroundLocationUpdates = true;

            UIApplication.SharedApplication.BeginInvokeOnMainThread(() =>
            {
                _locationManager.RequestAlwaysAuthorization();
            });
            if (!CLLocationManager.IsMonitoringAvailable(typeof(CLCircularRegion)))
#else
            if (!CLLocationManager.IsMonitoringAvailable(new ObjCRuntime.Class("CLCircularRegion")))
#endif
            {
                Status = GeofenceMonitorStatus.NotAvailable;
            }
            else
            {
                maxRegion = _locationManager.MaximumRegionMonitoringDistance;
                _locationManager.RegionEntered += _locationManager_RegionEntered;
                _locationManager.RegionLeft    += _locationManager_RegionLeft;
            }
#elif WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE
            _monitor = Windows.Devices.Geolocation.Geofencing.GeofenceMonitor.Current;
#elif TIZEN
            _locator                      = new Tizen.Location.Locator(Tizen.Location.LocationType.Hybrid);
            _locator.ZoneChanged         += _locator_ZoneChanged;
            _locator.ServiceStateChanged += _locator_ServiceStateChanged;
#endif
        }
Exemple #3
0
        public void StopMonitoringRegion(CLCircularRegion region)
        {
            if (CLLocationManager.LocationServicesEnabled)
            {
                if (CLLocationManager.Status != CLAuthorizationStatus.Denied)
                {
                    if (CLLocationManager.IsMonitoringAvailable(typeof(CLCircularRegion)))
                    {
                        LocMgr.StopMonitoring(region);
                        Console.WriteLine("Stopped monitoring region: {0}", region.ToString());
                    }
                    else
                    {
                        Console.WriteLine("This app requires region monitoring, which is unavailable on this device");
                    }

                    // Get some output from our manager in case of failure
                    LocMgr.Failed += (o, e) => {
                        Console.WriteLine(e.Error);
                    };
                }
                else
                {
                    Console.WriteLine("App is not authorized to use location data");
                }
            }
            else
            {
                //Let the user know that they need to enable LocationServices
                Console.WriteLine("Location services not enabled, please enable this in your Settings");
            }
        }
Exemple #4
0
        /// <summary>
        /// 位置情報利用の認証状態が変わった際に、位置情報のモニタリングを開始します。
        /// </summary>
        /// <param name="manager"></param>
        /// <param name="status"></param>
        public override void AuthorizationChanged(CLLocationManager manager, CLAuthorizationStatus status)
        {
            var adapter = new DbAdapter_iOS();

            adapter.AddDeviceLog($"位置情報の認証状態が更新", status.ToString()); // TODO ステータス名表示に

            if (status == CLAuthorizationStatus.AuthorizedAlways || status == CLAuthorizationStatus.AuthorizedWhenInUse)
            {
                //iBeacon領域判定の有効化
                if (CLLocationManager.IsMonitoringAvailable(typeof(CLBeaconRegion)))
                {
                    研究室領域.NotifyEntryStateOnDisplay = false;
                    研究室領域.NotifyOnEntry             = true;
                    研究室領域.NotifyOnExit = true;

                    manager.StartMonitoring(研究室領域);
                }

                //ジオフェンス領域の有効化
                if (CLLocationManager.IsMonitoringAvailable(typeof(CLCircularRegion)))
                {
                    foreach (var gr in 学内領域)
                    {
                        gr.NotifyOnEntry = true;
                        gr.NotifyOnExit  = true;
                        manager.StartMonitoring(gr);
                    }
                }
            }
            else
            {
                //位置情報利用の許可を貰う
                manager.RequestAlwaysAuthorization();
            }
        }
Exemple #5
0
        public static async Task <AccessState> RequestGeofenceAccess(this CLLocationManager locationManager)
        {
            if (!CLLocationManager.LocationServicesEnabled)
            {
                return(AccessState.Disabled);
            }

            if (!CLLocationManager.IsMonitoringAvailable(typeof(CLCircularRegion)))
            {
                return(AccessState.NotSupported);
            }

            var gdelegate = (GeofenceManagerDelegate)locationManager.Delegate;
            var result    = CLLocationManager.Status;

            if (result == CLAuthorizationStatus.NotDetermined)
            {
                var tcs     = new TaskCompletionSource <CLAuthorizationStatus>();
                var handler = new EventHandler <CLAuthorizationStatus>((sender, status) => tcs.TrySetResult(status));
                gdelegate.AuthStatusChanged += handler;
                locationManager.RequestAlwaysAuthorization();

                result = await tcs.Task;
                gdelegate.AuthStatusChanged -= handler;
            }
            return(result.FromNative(true));
        }
Exemple #6
0
        public bool BluetoothIsAvailableOnThisDevice()
        {
            bool locationServiceSupported = CLLocationManager.IsMonitoringAvailable(typeof(CLBeaconRegion));
            bool bluetoothSupported       = !(_bluetoothAvailability == CBCentralManagerState.Unsupported);

            return(locationServiceSupported && bluetoothSupported);
        }
Exemple #7
0
        private void StartRanging()
        {
            if (viewModel == null || viewModel.Quest == null)
            {
                return;
            }

            if (ranging)
            {
                return;
            }


            if (!CLLocationManager.IsMonitoringAvailable(typeof(CLBeaconRegion)))
            {
                return;
            }


            ranging = true;

            if (secretRegion == null)
            {
                secretRegion = new CLBeaconRegion(new NSUuid(viewModel.UUID), 9999, BeaconId);
            }


            if (beaconRegion != null)
            {
                manager.StartRangingBeacons(beaconRegion);
            }

            managerSecret.StartRangingBeacons(secretRegion);
        }
Exemple #8
0
        public static AccessState GetCurrentStatus <T>(this CLLocationManager locationManager, bool background) where T : CLRegion
        {
            if (!CLLocationManager.IsMonitoringAvailable(typeof(T)))
            {
                return(AccessState.NotSupported);
            }

            return(locationManager.GetCurrentStatus(background));
        }
Exemple #9
0
        public void Start()
        {
            Debug.WriteLine($"{nameof(Start)}()", LogTag);

            if (!CLLocationManager.IsMonitoringAvailable(typeof(CLBeaconRegion)))
            {
                Debug.WriteLine("Cannot monitor beacon regions, my bad.", LogTag);
                return;
            }

            _locationManager.StartMonitoring(_clBeaconRegion);
        }
Exemple #10
0
        void StartBeaconMonitoring()
        {
            var isAvailable = CLLocationManager.IsMonitoringAvailable(typeof(CLRegion));

            if (CLLocationManager.IsRangingAvailable && isAvailable)
            {
                locationMgr.StartRangingBeacons(beaconRegion);
                locationMgr.StartMonitoring(beaconRegion);
            }
            Console.WriteLine("CLLocationManager.IsRangingAvailable && CLLocationManager.IsMonitoringAvailable(typeof(CLRegion)");
            Console.WriteLine(CLLocationManager.IsRangingAvailable.ToString() + " & " + CLLocationManager.IsMonitoringAvailable(typeof(CLRegion)));
        }
Exemple #11
0
 protected virtual void SetupGeofenceService()
 {
     if (CLLocationManager.IsMonitoringAvailable(typeof(CLCircularRegion)))
     {
         LocationManager.DidStartMonitoringForRegion += StartedMonitorRegionHandler;
         LocationManager.RegionEntered += RegionEnteredHandler;
         LocationManager.RegionLeft    += RegionLeftHandler;
     }
     else
     {
         Log.LogMessage("This app requires region monitoring, which is unavailable on this device");
     }
 }
        public void StartMonitoring()
        {
            if (CLLocationManager.IsMonitoringAvailable(typeof(CLBeaconRegion)))
            {
                // Match all beacons with the specified UUID
                var proximityUUID = new NSUuid("39ED98FF-2900-441A-802F-9C398FC199D2");
                var beaconID      = "com.example.myBeaconRegion";

                // Create the region and begin monitoring it.
                var region = new CLBeaconRegion(proximityUUID, beaconID);
                this.locationManager.StartMonitoring(region);
            }
        }
        /// <summary>
        /// Stops monitoring region
        /// </summary>
        /// <param name="regionIdentifier"></param>
        public void StopMonitoring(string regionIdentifier)
        {
            if (CLLocationManager.IsMonitoringAvailable(typeof(CLRegion)))
            {
                RemoveRegionMonitoring(regionIdentifier);

                CrossGeofence.GeofenceListener.OnMonitoringStopped(regionIdentifier);

                if (mRegions.Count == 0)
                {
                    CrossGeofence.GeofenceListener.OnMonitoringStopped();
                }
            }
        }
Exemple #14
0
        // We need to perform a lot of checks to make sure location data and region monitoring are available and enabled.
        // For simplicity, we're logging errors in the console.

        public void StartMonitoringRegion(CLCircularRegion region)
        {
            Console.Write("Entro al monitoreo");
            Console.Write(CLLocationManager.LocationServicesEnabled);
            if (CLLocationManager.LocationServicesEnabled)
            {
                if (CLLocationManager.Status != CLAuthorizationStatus.Denied)
                {
                    if (CLLocationManager.IsMonitoringAvailable(typeof(CLCircularRegion)))
                    {
                        //LocMgr.DesiredAccuracy = 1;

                        LocMgr.RegionEntered += (o, e) => {
                            Console.WriteLine("Just entered " + e.Region.ToString());
                            RegionEntered(this, new RegionChangedEventArgs((CLCircularRegion)e.Region));
                        };

                        LocMgr.RegionLeft += (o, e) => {
                            Console.WriteLine("Just left " + e.Region.ToString());
                            RegionLeft(this, new RegionChangedEventArgs((CLCircularRegion)e.Region));
                        };

                        LocMgr.DidStartMonitoringForRegion += (o, e) => {
                            Console.WriteLine("Now monitoring region {0}", e.Region.ToString());
                        };

                        LocMgr.StartMonitoring(region);
                    }
                    else
                    {
                        Console.WriteLine("This app requires region monitoring, which is unavailable on this device");
                    }
                }
                else
                {
                    Console.WriteLine("App is not authorized to use location data");
                }

                // Get some output from our manager in case of failure
                LocMgr.Failed += (o, e) => {
                    Console.WriteLine(e.Error);
                };
            }
            else
            {
                //Let the user know that they need to enable LocationServices
                Console.WriteLine("Location services not enabled, please enable this in your Settings");
            }
        }
        /// <summary>
        /// Checks if is available for monitoring
        /// </summary>
        /// <returns></returns>
        public bool AvailableForMonitoring()
        {
            bool retVal = false;

            RequestAlwaysAuthorization();


            if (!CLLocationManager.LocationServicesEnabled)
            {
                string message = string.Format("{0} - {1}", CrossGeofence.Id, "You need to enable Location Services");
                System.Diagnostics.Debug.WriteLine(message);
                CrossGeofence.GeofenceListener.OnError(message);
            }
            else if (CLLocationManager.Status == CLAuthorizationStatus.Denied || CLLocationManager.Status == CLAuthorizationStatus.Restricted)
            {
                string message = string.Format("{0} - {1}", CrossGeofence.Id, "You need to authorize Location Services");
                System.Diagnostics.Debug.WriteLine(message);
                CrossGeofence.GeofenceListener.OnError(message);
            }
            else if (CLLocationManager.IsMonitoringAvailable(typeof(CLRegion)))
            {
                if (RequestNotificationPermission)
                {
                    using (var pool = new NSAutoreleasePool())
                    {
                        pool.InvokeOnMainThread(() => {
                            var settings = UIUserNotificationSettings.GetSettingsForTypes(
                                UIUserNotificationType.Alert
                                | UIUserNotificationType.Badge
                                | UIUserNotificationType.Sound,
                                new NSSet());
                            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);
                        });
                    }
                }
                retVal = true;
            }
            else
            {
                string message = string.Format("{0} - {1}", CrossGeofence.Id, "Not available for monitoring");
                System.Diagnostics.Debug.WriteLine(message);
                CrossGeofence.GeofenceListener.OnError(message);
            }



            return(retVal);
        }
Exemple #16
0
        public void Stop()
        {
            Debug.WriteLine($"{nameof(Stop)}()", LogTag);


            if (CLLocationManager.IsMonitoringAvailable(typeof(CLBeaconRegion)))
            {
                _locationManager.StopMonitoring(_clBeaconRegion);
            }
            else
            {
                Debug.WriteLine("Beacon monitor stop failed, monitoring not available.", LogTag);
            }

            WatcherStopped?.Invoke(sender: this, e: new BeaconError(BeaconError.BeaconErrorType.Success));
        }
Exemple #17
0
        /// <inheritdoc />
        public bool IsMonitoringAvailable(Class regionClass) =>

        // TODO: Rodney gets to fix this
        CLLocationManager.IsMonitoringAvailable(regionClass);