Пример #1
0
        private void StartMonitoringHome()
        {
            if (Settings.SettingsSet() && Settings.GeographicRegionSet())
            {
                locationManager.AuthorizationChanged += (s, e) =>
                {
                    if (e.Status == CLAuthorizationStatus.AuthorizedAlways)
                    {
                        locationManager.StartMonitoring(HomeRegion());
                    }
                };

                locationManager.RegionEntered += async(s, e) => await OnApprochingHome();

                locationManager.RegionLeft += async(s, e) => await CheckIfGarageDoorIsOpen();

                locationManager.RequestAlwaysAuthorization();

                if (locationManager.MonitoredRegions.Count() == 0)
                {
                    try {
                        locationManager.StartMonitoring(HomeRegion());
                    }
                    catch {}
                }
            }
        }
Пример #2
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();
            }
        }
 public BeaconLocateriOS()
 {
     SetupBeaconRanging();
     locationManager.StartMonitoring(rBeaconRegion);
     locationManager.RequestState(rBeaconRegion);
     locationManager.StartMonitoring(eBeaconRegion);
     locationManager.RequestState(eBeaconRegion);
 }
Пример #4
0
        internal void AddRegion(CLRegion region)
        {
#if __IOS__
            _locationManager.StartMonitoring(region, CLLocation.AccuracyBest);
#else
            _locationManager.StartMonitoring(region);
#endif
            Status = GeofenceMonitorStatus.Ready;
        }
Пример #5
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            locMan = new CLLocationManager();
            locMan.RequestWhenInUseAuthorization();
            locMan.RequestAlwaysAuthorization();
            // Geocode a city to get a CLCircularRegion,
            // and then use our location manager to set up a geofence
            button.TouchUpInside += (o, e) => {
                // clean up monitoring of old region so they don't pile up
                if (region != null)
                {
                    locMan.StopMonitoring(region);
                }

                // Geocode city location to create a CLCircularRegion - what we need for geofencing!
                var taskCoding = geocoder.GeocodeAddressAsync("Cupertino");
                taskCoding.ContinueWith((addresses) => {
                    CLPlacemark placemark = addresses.Result [0];
                    region = (CLCircularRegion)placemark.Region;
                    locMan.StartMonitoring(region);
                });
            };


            // This gets called even when the app is in the background - try it!
            locMan.RegionEntered += (sender, e) => {
                Console.WriteLine("You've entered the region");
            };

            locMan.RegionLeft += (sender, e) => {
                Console.WriteLine("You've left the region");
            };
        }
        void AddRegion(GeofenceCircularRegion region)
        {
            CLRegion cRegion = null;


            if (UIDevice.CurrentDevice.CheckSystemVersion(7, 0))
            {
                cRegion = new CLCircularRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
            }
            else
            {
                cRegion = new CLRegion(new CLLocationCoordinate2D(region.Latitude, region.Longitude), (region.Radius > locationManager.MaximumRegionMonitoringDistance) ? locationManager.MaximumRegionMonitoringDistance : region.Radius, region.Id);
            }


            cRegion.NotifyOnEntry = region.NotifyOnEntry || region.NotifyOnStay;
            cRegion.NotifyOnExit  = region.NotifyOnExit;


            locationManager.StartMonitoring(cRegion);

            // Request state for this region, putting request behind a timer per thread: http://stackoverflow.com/questions/24543814/diddeterminestate-not-always-called
            Task.Run(async() => {
                await Task.Delay(TimeSpan.FromSeconds(2));
                locationManager.RequestState(cRegion);
            });
        }
 public BeaconLocateriOS()
 {
     //iBeacon-Einstellungen laden und die Suche nach iBeacon beginnen
     SetupBeaconRanging();
     locationManager.StartMonitoring(rBeaconRegion);
     locationManager.RequestState(rBeaconRegion);
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            //usig KVO to tracking content change updates for the view
            _locationDelegate.AddObserver(this, (NSString)CoreLocation.CoreLocationPropertyName.CustomContent.ToString(), NSKeyValueObservingOptions.New, IntPtr.Zero);

            _locationManager = new CLLocationManager();

            var beaconId = new NSUuid(Globals.BroadCastUUid);

            _beaconRegion = new CLBeaconRegion(beaconId, Globals.BeaconRegion);

            _beaconRegion.NotifyEntryStateOnDisplay = true;

            _locationManager.Delegate = _locationDelegate;

            _locationManager.StartMonitoring(_beaconRegion);


            //I have tested this and this viewdidload event fires momentarily IF :
            //1) the app is shutdown
            //2) you are actively monitoring regions
            //3) you enter a region being monitorings
            //You will get about 10-11 beacon DidRangeEvnts when the app
            //fires up form the background on region enter/exit.
            //I removed notificationcenter updates since :
            //1) if the user happens to enter a region with a beacon in near prox
            //he/she will only get one notification since I am tracking how often I pop
            //content withing BeaconContentManager.
            RangeBeacons();
        }
Пример #9
0
        public void SetUpLocationManger()
        {
            beaconUUID = new NSUuid(BeaconCreds.UUID);

            LocationManager = new CLLocationManager();
            LocationManager.RequestAlwaysAuthorization();
            LocationManager.StartUpdatingHeading();

            if (BeaconCreds.BeaconMonitoring == BeaconMonitoring.Proximity)
            {
                BeaconsRegion = new CLBeaconRegion(beaconUUID, BeaconCreds.BeaconsRegion);

                LocationManager.StartRangingBeacons(BeaconsRegion);
            }
            else
            {
                BeaconsRegionsList = new List <CLBeaconRegion>();

                foreach (Beacon beacon in Beacons.BeaconList)
                {
                    CLBeaconRegion tempRegion = new CLBeaconRegion(beaconUUID, (ushort)beacon.Major, (ushort)beacon.Minor, beacon.RegionId);
                    tempRegion.NotifyEntryStateOnDisplay = true;
                    tempRegion.NotifyOnEntry             = true;
                    tempRegion.NotifyOnExit = true;

                    BeaconsRegionsList.Add(tempRegion);

                    LocationManager.StartMonitoring(tempRegion);
                }
            }
        }
Пример #10
0
        public void StartBeacon()
        {
            System.Diagnostics.Debug.WriteLine("StartBeacon");

            _locationMgr.RequestAlwaysAuthorization();
            _locationMgr.DidRangeBeacons   += HandleDidRangeBeacons;
            _locationMgr.DidDetermineState += HandleDidDetermineState;
            _locationMgr.PausesLocationUpdatesAutomatically = false;
            _locationMgr.StartUpdatingLocation();
            _locationMgr.RequestAlwaysAuthorization();

            _listOfCLBeaconRegion.Add(clBeaconRegion);
            _locationMgr.StartMonitoring(clBeaconRegion);
            _locationMgr.StartRangingBeacons(clBeaconRegion);

            //            #if DEBUG
            //            var beacon = _listOfCLBeaconRegion.First();
            //            string uuid = beacon.ProximityUuid.AsString ();
            //            var major = (ushort)beacon.Major;
            //            var minor = (ushort)beacon.Minor;
            //
            //            Mvx.Resolve<IMvxMessenger>().Publish<BeaconChangeProximityMessage> (
            //                new BeaconChangeProximityMessage (this, uuid, major, minor)
            //            );
            //            #endif
        }
Пример #11
0
 void BeaconManagerAuthorizationStatusChanged(object sender, CLAuthorizationChangedEventArgs e)
 {
     if (e.Status == CLAuthorizationStatus.AuthorizedAlways)
     {
         _beaconManager.StartMonitoring(_beaconRegion);
     }
 }
Пример #12
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            RegisterNotifications();

            LocationManager = new CLLocationManager();
            BeaconRegion    = new CLBeaconRegion(RegionUuid, 24986, "Community Days 2016");
            BeaconRegion.NotifyEntryStateOnDisplay = true;
            BeaconRegion.NotifyOnEntry             = true;
            BeaconRegion.NotifyOnExit = true;

            LocationManager.AuthorizationChanged += (s, e) =>
            {
                if (e.Status != CLAuthorizationStatus.AuthorizedAlways)
                {
                    return;
                }

                LocationManager.RegionEntered += (s1, e1) =>
                {
                    SendNotification("Benvenuti alla sessione sui Beacon");
                };
                LocationManager.RegionLeft += (s1, e1) =>
                {
                    SendNotification("Non dimenticate di dare il vostro feedback");
                };

                LocationManager.StartMonitoring(BeaconRegion);
            };

            LocationManager.RequestAlwaysAuthorization();
            return(true);
        }
Пример #13
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            locMan = new CLLocationManager();
            locMan.RequestWhenInUseAuthorization();
            locMan.RequestAlwaysAuthorization();
            // Geocode a city to get a CLCircularRegion,
            // and then use our location manager to set up a geofence
            button.TouchUpInside += (o, e) => {

                // clean up monitoring of old region so they don't pile up
                if(region != null)
                {
                    locMan.StopMonitoring(region);
                }

                // Geocode city location to create a CLCircularRegion - what we need for geofencing!
                var taskCoding = geocoder.GeocodeAddressAsync ("Cupertino");
                taskCoding.ContinueWith ((addresses) => {
                    CLPlacemark placemark = addresses.Result [0];
                    region = (CLCircularRegion)placemark.Region;
                    locMan.StartMonitoring(region);

                });
            };

            // This gets called even when the app is in the background - try it!
            locMan.RegionEntered += (sender, e) => {
                Console.WriteLine("You've entered the region");
            };

            locMan.RegionLeft += (sender, e) => {
                Console.WriteLine("You've left the region");
            };
        }
Пример #14
0
        public override bool FinishedLaunching(UIApplication application,
                                               NSDictionary launchOptions)
        {
            RegisterNotifications();

            LocationManager = new CLLocationManager();

            LocationManager.AuthorizationChanged += (s, e) =>
            {
                if (e.Status != CLAuthorizationStatus.AuthorizedAlways)
                {
                    return;
                }

                var region = new CLBeaconRegion(_regionUuid, "Evolve Region");

                LocationManager.RegionEntered += (s1, e1) => SendEnterNotification();
                LocationManager.RegionLeft    += (s1, e1) => SendExitNotification();

                LocationManager.StartMonitoring(region);
            };

            LocationManager.RequestAlwaysAuthorization();

            return(true);
        }
Пример #15
0
        public void StartBeacon()
        {
            _locationMgr.RequestAlwaysAuthorization();

            // Authorization
            _locationMgr.AuthorizationChanged += DidAuthorizationChanged;

            // Monitoring
            _locationMgr.RegionEntered += DidRegionEntered;
            _locationMgr.RegionEntered += DidRegionLeft;

            // Ranging
            _locationMgr.DidRangeBeacons   += DidRangeBeacons;
            _locationMgr.DidDetermineState += DidDetermineState;
            _locationMgr.PausesLocationUpdatesAutomatically = false;

            _locationMgr.StartUpdatingLocation();
            _locationMgr.RequestAlwaysAuthorization();

            _fieldRegion = new CLBeaconRegion(new NSUuid(AppConstants.AppUUID), "Covid19Radar");
            _fieldRegion.NotifyOnEntry             = true;
            _fieldRegion.NotifyOnExit              = true;
            _fieldRegion.NotifyEntryStateOnDisplay = true;
            _locationMgr.StartMonitoring(_fieldRegion);

            System.Diagnostics.Debug.WriteLine("Start");
        }
Пример #16
0
    void Monitor()
    {
        // don't advertise and monitor at the same time
        StopAdvertise();

        if (isMonitoring)
        {
            Log("Already monitoring.");
            return;
        }

        if (locationManager == null)
        {
            locationManager = new CLLocationManager();
        }

        locationManager.DidStartMonitoring += DidStartMonitoringForRegion;
        locationManager.DidEnter           += DidEnterRegion;
        locationManager.DidExit            += DidExitRegion;
        locationManager.DidRangeBeacons    += DidRangeBeacons;
        locationManager.StartMonitoring(beaconRegion);
        locationManager.StartRangingBeaconsInRegion(beaconRegion);

        Log("Monitoring.");
        isMonitoring = true;
    }
        protected override void StartMonitoringInternal(IList <BeaconModel> beaconList)
        {
            _locationManager.RequestAlwaysAuthorization();

            _locationManager.DidRangeBeacons   += LocationManager_DidRangeBeacons;
            _locationManager.DidDetermineState += LocationManager_DidDetermineState;;

            _locationManager.PausesLocationUpdatesAutomatically = false;

            _locationManager.StartUpdatingLocation();

            _locationManager.RequestAlwaysAuthorization();

            foreach (var beacon in beaconList)
            {
                var clBeaconRegion = new CLBeaconRegion(new NSUuid(beacon.UUID), beacon.Major, beacon.Minor, "custom_region_id");

                clBeaconRegion.NotifyEntryStateOnDisplay = true;
                clBeaconRegion.NotifyOnEntry             = true;
                clBeaconRegion.NotifyOnExit = true;

                _beaconRegions.Add(clBeaconRegion);

                _locationManager.StartMonitoring(clBeaconRegion);
                _locationManager.StartRangingBeacons(clBeaconRegion);

                Debug.WriteLine($"StartMonitoring {beacon.UUID}");
            }
        }
Пример #18
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            // Override point for customization after application launch.
            // If not required for your application you can safely delete this method

            RegisterNotifications();

            LocationManager = new CLLocationManager();
            BeaconRegion    = new CLBeaconRegion(RegionUuid, "ITCamp 2016");
            BeaconRegion.NotifyEntryStateOnDisplay = true;
            BeaconRegion.NotifyOnEntry             = true;
            BeaconRegion.NotifyOnExit = true;

            LocationManager.AuthorizationChanged += (s, e) =>
            {
                if (e.Status != CLAuthorizationStatus.AuthorizedAlways)
                {
                    return;
                }

                LocationManager.RegionEntered += (s1, e1) => SendNotification("Welcome to the Beacon Session");
                LocationManager.RegionLeft    += (s1, e1) => SendNotification("Goodbye remember to compile the evaluation form");

                LocationManager.StartMonitoring(BeaconRegion);
            };

            LocationManager.RequestAlwaysAuthorization();
            return(true);
        }
Пример #19
0
        // The user left the refresh zone.  Get a new catalog of bubbles from the server.
        async void Refresh(object sender, CLRegionEventArgs e)
        {
            if (credentials.BasicAuthString.Length > 0 && (e == null || e.Region.Identifier.Equals("RefreshZone"))) // Ignore location bubbles.
            {
                // Get the user's location and code it as the bubble zone.
                CLLocation location  = LocMgr.Location;
                double     latitude  = location.Coordinate.Latitude;  // TBD double
                double     longitude = location.Coordinate.Longitude; // TBD double
                Debug.WriteLine(">>>>> Refreshing at " + latitude.ToString() + ", " + longitude.ToString());
                Location loc = new Location(latitude, longitude);
                // Get all the bubbles in the zone.
                string json = await WebApiPost("api/Bubble", loc);

                BubbleCatalog = (List <BubbleMobile>)JsonConvert.DeserializeObject(json, typeof(List <BubbleMobile>));

                // At the last possible moment, delete all the existing bubbles.
                foreach (CLCircularRegion r in LocMgr.MonitoredRegions)
                {
                    LocMgr.StopMonitoring(r);
                }

                // Set an event handler for each bubble in the new list.
                foreach (BubbleMobile bubble in BubbleCatalog)
                {
                    if (bubble.Id == 0) // Refresh zone bubble.
                    {
                        Debug.WriteLine(">>>>> Adding refresh zone");
                        // Redefine the refresh zone and give it an event handler.
                        CLCircularRegion refreshRegion = new CLCircularRegion(new CLLocationCoordinate2D(latitude, longitude), bubble.Radius, "RefreshZone");
                        LocMgr.StartMonitoring(refreshRegion);
                    }
                    else // Poppable bubble.
                    {
                        CLCircularRegion bubbleRegion = new CLCircularRegion(new CLLocationCoordinate2D((double)bubble.Latitude, (double)bubble.Longitude), bubble.Radius, bubble.Id.ToString());
                        LocMgr.StartMonitoring(bubbleRegion);
                        Debug.WriteLine(">>>>> Adding bubble #" + bubble.Id.ToString());
                        // Check to see if we're already inside the bubble.  This will not raise a "RegionEntered" event.
                        if (bubbleRegion.Contains(new CLLocationCoordinate2D(latitude, longitude)))
                        {
                            Debug.WriteLine(">>>>> Inside bubble #" + bubble.Id.ToString() + " before pop");
                            Pop(null, new CLRegionEventArgs(bubbleRegion));
                            Debug.WriteLine(">>>>> Inside bubble #" + bubble.Id.ToString() + " after pop");
                        }
                    }
                }
            }
        }
Пример #20
0
        partial void buttonCreateClicked(UIButton sender)
        {
            //CLRegion aRegion = new CLRegion();
            // locMan.StartMonitoring(aRegion);
            CLCircularRegion aRegion2 = new CLCircularRegion(new CLLocationCoordinate2D(30.432, 97.7360), 100, "apple test");

            locMan.StartMonitoring(aRegion2);
        }
Пример #21
0
        public void StartMonitoringBeaconRegion(string uuid, ushort major, ushort minor, string identifier)
        {
            var beaconUUID = new NSUuid(uuid);

            CLBeaconRegion beaconRegion = new CLBeaconRegion(beaconUUID, major, minor, identifier)
            {
                NotifyEntryStateOnDisplay = true,
                NotifyOnEntry             = true,
                NotifyOnExit = true
            };

            if (_manager != null)
            {
                _manager.StartMonitoring(beaconRegion);
                _logger?.Information($"iOS: Started monitoring: {identifier}");
            }
        }
Пример #22
0
 public void StartMonitoring(GeofenceRegion region)
 {
     UIApplication.SharedApplication.InvokeOnMainThread(() =>
     {
         var native = this.ToNative(region);
         locationManager.StartMonitoring(native);
     });
 }
        void LocationManagerAuthorizationChanged(object sender, CLAuthorizationChangedEventArgs e)
        {
            Debug.WriteLine("Authorisation state: {0}", e.Status);

            if (e.Status == CLAuthorizationStatus.AuthorizedAlways)
            {
                _locationManager.StartMonitoring(_region);
            }
        }
Пример #24
0
        public void StartBeacon()
        {
            System.Diagnostics.Debug.WriteLine("StartBeacon");



            _listOfCLBeaconRegion.Add(_fieldRegion);
            _beaconManager.StartMonitoring(_fieldRegion);
        }
Пример #25
0
        void MonitorCurrentRegion(double lat, double lon, double radius, string identifier)
        {
            CLRegion region = new CLRegion(new CLLocationCoordinate2D(lat, lon), radius, identifier);

            region.NotifyOnExit  = true;
            region.NotifyOnEntry = false;

            _clManager.StartMonitoring(region);
        }
Пример #26
0
        public BeaconMonitor()
        {
            locationManager = new CLLocationManager();
            var beaconRegion = new CLBeaconRegion(new NSUuid(PollViewModel.LOOKUP_UUID), "My Beacon")
            {
                NotifyEntryStateOnDisplay = true,
                NotifyOnEntry             = true
            };

            locationManager.RegionEntered += (s, e) => {
                if (e.Region.Identifier == "My Beacon")
                {
                    Console.WriteLine("Found My Beacon");

                    locationManager.StartRangingBeacons(beaconRegion);

                    locationManager.DidRangeBeacons += (lm, e2) => {
                        if (e2.Beacons.Length > 0)
                        {
                            foreach (var b in e2.Beacons)
                            {
                                if (b.Proximity != CLProximity.Unknown)
                                {
                                    Console.WriteLine("UUID: {0} | Major: {1} | Minor: {2} | Accuracy: {3} | Proximity: {4} | RSSI: {5}", b.ProximityUuid, b.Major, b.Minor, b.Accuracy, b.Proximity, b.Rssi);
                                    var exists = false;
                                    foreach (var beacon in Beacons)
                                    {
                                        if (beacon.Minor.Equals(b.Minor.ToString()))
                                        {
                                            beacon.CurrentDistance = Math.Round(b.Accuracy, 2);
                                            SetProximity(b, beacon);
                                            exists = true;
                                        }
                                    }

                                    if (!exists)
                                    {
                                        var newBeacon = new BeaconItem
                                        {
                                            Minor           = b.Minor.ToString(),
                                            Name            = "",
                                            CurrentDistance = Math.Round(b.Accuracy, 2)
                                        };
                                        SetProximity(b, newBeacon);
                                        Beacons.Add(newBeacon);
                                    }
                                }
                            }
                        }
                    };
                }
            };
            locationManager.StartMonitoring(beaconRegion);
        }
Пример #27
0
        public void listen()
        {
            var gimbalUUID = new NSUuid(uuid_gimbal);

            beaconRegion = new CLBeaconRegion(gimbalUUID, gimbalId);

            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry             = true;
            beaconRegion.NotifyOnExit = true;

            locationManager = new CLLocationManager();

            locationManager.RequestAlwaysAuthorization();

            locationManager.RegionEntered += (object sender, CLRegionEventArgs e) =>
            {
                if (e?.Region.Identifier == gimbalId)
                {
                    FoundGimbal("There's a gimbal nearby!");
                }
            };

            locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) =>
            {
                if (e?.Beacons.Length > 0)
                {
                    var beacon = e.Beacons.FirstOrDefault();

                    switch (beacon.Proximity)
                    {
                    case CLProximity.Immediate:
                        OnUpdateDisplay(new GimbalEventArgs("You found the gimbal!", Color.Green));
                        break;

                    case CLProximity.Near:
                        OnUpdateDisplay(new GimbalEventArgs("You're near the gimbal!", Color.Yellow));
                        break;

                    case CLProximity.Far:
                        OnUpdateDisplay(new GimbalEventArgs("You're far from the gimbal!", Color.Red));
                        break;

                    case CLProximity.Unknown:
                        OnUpdateDisplay(new GimbalEventArgs("Got no idea where the gimbal is!", Color.Gray));
                        break;
                    }

                    previousProximity = beacon.Proximity;
                }
            };

            locationManager.StartMonitoring(beaconRegion);
            locationManager.StartRangingBeacons(beaconRegion);
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			Near = UIImage.FromBundle ("Images/square_near");
			Far = UIImage.FromBundle ("Images/square_far");
			Immediate = UIImage.FromBundle ("Images/square_immediate");
			Unknown = UIImage.FromBundle ("Images/square_unknown");

			beaconUUID = new NSUuid (uuid);
			beaconRegion = new CLBeaconRegion (beaconUUID, beaconMajor, beaconId);


			beaconRegion.NotifyEntryStateOnDisplay = true;
			beaconRegion.NotifyOnEntry = true;
			beaconRegion.NotifyOnExit = true;

			locationmanager = new CLLocationManager ();

			locationmanager.RegionEntered += (object sender, CLRegionEventArgs e) => {
				if (e.Region.Identifier == beaconId) {

					var notification = new UILocalNotification () { AlertBody = "The Xamarin beacon is close by!" };
					UIApplication.SharedApplication.CancelAllLocalNotifications();
					UIApplication.SharedApplication.PresentLocationNotificationNow (notification);
				}
			};


			locationmanager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
				if (e.Beacons.Length > 0) {

					CLBeacon beacon = e.Beacons [0];
					//this.Title = beacon.Proximity.ToString() + " " +beacon.Major + "." + beacon.Minor;
				}
					
				dataSource.Beacons = e.Beacons;
				TableView.ReloadData();
			};







			locationmanager.StartMonitoring (beaconRegion);
			locationmanager.StartRangingBeacons (beaconRegion);



			TableView.Source = dataSource = new DataSource (this);
		}
Пример #29
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)));
        }
Пример #30
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);
        }
Пример #31
0
        public void StartBeacon()
        {
            System.Diagnostics.Debug.WriteLine("StartBeacon");

            _beaconManager.RequestAlwaysAuthorization();
            _beaconManager.PausesLocationUpdatesAutomatically = false;
            _beaconManager.AllowsBackgroundLocationUpdates    = true;
            _beaconManager.ShowsBackgroundLocationIndicator   = true;

            _listOfCLBeaconRegion.Add(_fieldRegion);
            _beaconManager.StartMonitoring(_fieldRegion);
        }
Пример #32
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            Near      = UIImage.FromBundle("Images/square_near");
            Far       = UIImage.FromBundle("Images/square_far");
            Immediate = UIImage.FromBundle("Images/square_immediate");
            Unknown   = UIImage.FromBundle("Images/square_unknown");

            beaconUUID   = new NSUuid(uuid);
            beaconRegion = new CLBeaconRegion(beaconUUID, beaconMajor, beaconId);


            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry             = true;
            beaconRegion.NotifyOnExit = true;

            locationmanager = new CLLocationManager();

            locationmanager.RegionEntered += (object sender, CLRegionEventArgs e) => {
                if (e.Region.Identifier == beaconId)
                {
                    var notification = new UILocalNotification()
                    {
                        AlertBody = "The Xamarin beacon is close by!"
                    };
                    UIApplication.SharedApplication.CancelAllLocalNotifications();
                    UIApplication.SharedApplication.PresentLocationNotificationNow(notification);
                }
            };


            locationmanager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                if (e.Beacons.Length > 0)
                {
                    CLBeacon beacon = e.Beacons [0];
                    //this.Title = beacon.Proximity.ToString() + " " +beacon.Major + "." + beacon.Minor;
                }

                dataSource.Beacons = e.Beacons;
                TableView.ReloadData();
            };



            locationmanager.StartMonitoring(beaconRegion);
            locationmanager.StartRangingBeacons(beaconRegion);



            TableView.Source = dataSource = new DataSource(this);
        }
Пример #33
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			// Perform any additional setup after loading the view, typically from a nib.

			var LocationManager = new CLLocationManager();
			LocationManager.RequestWhenInUseAuthorization ();
			LocationManager.RequestAlwaysAuthorization ();

			CLCircularRegion region = new CLCircularRegion (new CLLocationCoordinate2D (+46.833120, +15.34901), 1000.0, "FF Gussendorf");

			if (CLLocationManager.LocationServicesEnabled) {

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

				LocationManager.RegionEntered += (o, e) => {
					Console.WriteLine ("Just entered " + e.Region.ToString ());
				};

				LocationManager.RegionLeft += (o, e) => {
					Console.WriteLine ("Just left " + e.Region.ToString ());
				};

				LocationManager.Failed += (o, e) => {
					Console.WriteLine (e.Error);
				};

				LocationManager.UpdatedLocation += (o, e) => {
					Console.WriteLine ("Lat " + e.NewLocation.Coordinate.Latitude + ", Long " + e.NewLocation.Coordinate.Longitude);
				};

				LocationManager.LocationsUpdated += (o, e) => Console.WriteLine ("Location change received");

				LocationManager.StartMonitoring (region);
				LocationManager.StartMonitoringSignificantLocationChanges ();

				//LocationManager.StopMonitoringSignificantLocationChanges ();



			} else {
				Console.WriteLine ("This app requires region monitoring, which is unavailable on this device");
			}
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            var beaconRegion = new CLBeaconRegion (UUID, major, regionIdentifier);
            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry = true;
            beaconRegion.NotifyOnExit = true;

            locationMgr = new CLLocationManager ();

            locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => {
                if (e.Region.Identifier == regionIdentifier)
                {
                    UILocalNotification notification = new UILocalNotification () { AlertBody = "Beacon Located" };
                    UIApplication.SharedApplication.PresentLocationNotificationNow (notification);
                    titleLabel.Text = "Found Beacon!";
                }
            };

            locationMgr.RegionLeft += (object sender, CLRegionEventArgs e) => {
                if (e.Region.Identifier == regionIdentifier)
                {
                    titleLabel.Text = "Lost Beacon :(";
                }
            };

            locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                if (e.Beacons.Length > 0)
                {
                    var beacon = e.Beacons[0];
                    subTitleLabel.Text = e.Beacons[0].Proximity.ToString();
                    detailsLabel.Text = "Strength: " + beacon.Rssi + " Distance: " + beacon.Accuracy.ToString();
                }
            };

            locationMgr.StartMonitoring (beaconRegion);
            locationMgr.StartRangingBeacons (beaconRegion);
        }
        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();

            var beaconUUID = new NSUuid (uuid);
            var beaconRegion = new CLBeaconRegion (beaconUUID, beaconId);

            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry = true;
            beaconRegion.NotifyOnExit = true;

            locationManager = new CLLocationManager ();

            locationManager.RequestWhenInUseAuthorization ();

            locationManager.DidStartMonitoringForRegion += (object sender, CLRegionEventArgs e) => {
                locationManager.RequestState (e.Region);
            };

            locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => {
                if (e.Region.Identifier == beaconId) {
                    Console.WriteLine ("beacon region entered");
                }
            };

            locationManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => {

                switch (e.State) {
                case CLRegionState.Inside:
                    Console.WriteLine ("region state inside");
                    break;
                case CLRegionState.Outside:
                    Console.WriteLine ("region state outside");
                    break;
                case CLRegionState.Unknown:
                default:
                    Console.WriteLine ("region state unknown");
                    break;
                }
            };

            locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                if (e.Beacons.Length > 0) {

                    CLBeacon beacon = e.Beacons [0];

                    switch (beacon.Proximity) {
                    case CLProximity.Immediate:
                        message = "Immediate";
                        break;
                    case CLProximity.Near:
                        message = "Near";
                        break;
                    case CLProximity.Far:
                        message = "Far";
                        break;
                    case CLProximity.Unknown:
                        message = "Unknown";
                        break;
                    }

                    if (previousProximity != beacon.Proximity) {
                        Console.WriteLine (message);
                    }
                    previousProximity = beacon.Proximity;
                }
            };

            locationManager.StartMonitoring (beaconRegion);
            locationManager.StartRangingBeacons (beaconRegion);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            CLCircularRegion region = new CLCircularRegion(new CLLocationCoordinate2D(10.009176843388, 76.3615990792536), 20.0, "Jubin's Desk");

            locLabel = (UILabel)this.View.ViewWithTag(2004);
            locLabel1 = (UILabel)this.View.ViewWithTag(2005);
            statusLabel = (UILabel)this.View.ViewWithTag(2006);
            locLabel.Text = "Location...";
            locManager = new CLLocationManager();
            locManager.RequestAlwaysAuthorization ();
            //locManager.RequestWhenInUseAuthorization ();
            locManager.DesiredAccuracy = CLLocation.AccuracyBest;
            //locManager.DistanceFilter = 5.0;
            locManager.UpdatedLocation+=(object sender, CLLocationUpdatedEventArgs e) => {
                locLabel.Text = "Longitude: "+e.NewLocation.Coordinate.Longitude+" Lattitude: "+e.NewLocation.Coordinate.Latitude;
                System.Diagnostics.Debug.WriteLine("Longitude: "+e.NewLocation.Coordinate.Longitude+" Lattitude: "+e.NewLocation.Coordinate.Latitude);
            };
            /* this gets fired and works fine */
            locManager.LocationsUpdated+=(object sender, CLLocationsUpdatedEventArgs e) => {
                foreach (CLLocation aLocation in e.Locations)
                {
                    locLabel1.Text = "Longitude: "+aLocation.Coordinate.Longitude.ToString()+" Lattitude: "+aLocation.Coordinate.Latitude.ToString();
                    if (region.ContainsCoordinate(new CLLocationCoordinate2D(aLocation.Coordinate.Latitude, aLocation.Coordinate.Longitude)))
                    {
                        statusLabel.Text = "Normal location update: cordinates inside the region";
                    }
                    else
                    {
                        statusLabel.Text = "Normal location update: cordinates outside the region";
                    }
                }
            };
            locManager.StartUpdatingLocation();

            if (CLLocationManager.IsMonitoringAvailable (typeof(CLCircularRegion)))
            {
                /* This doesn't get fired */
                locManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => {
                    switch(e.State)
                    {
                        case CLRegionState.Inside:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Iniside...";
                            UIAlertView testAlert = new UIAlertView ();
                            testAlert.AddButton ("OK");
                            testAlert.Title = "Entered";
                            testAlert.Message = "Region "+e.Region.ToString();
                            testAlert.Show();
                        });
                        break;

                        case CLRegionState.Outside:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Outside...";
                            UIAlertView testAlert1 = new UIAlertView ();
                            testAlert1.AddButton ("OK");
                            testAlert1.Title = "Exit";
                            testAlert1.Message = "Region "+e.Region.ToString();
                            testAlert1.Show();
                        });
                        break;

                        case CLRegionState.Unknown:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Unknown state for region...";
                        });
                        break;
                        default:
                        break;
                    }
                };
                /* This works and gets fired */
                locManager.DidStartMonitoringForRegion += (o, e) => {
                    InvokeOnMainThread(()=>{
                        locManager.RequestState(e.Region);
                        locLabel.Text = "Now monitoring region : "+ e.Region.ToString ();
                    });
                };
                /* This doesn't get fired */
                locManager.DidVisit+=(object sender, CLVisitedEventArgs e) => {
                    InvokeOnMainThread(()=>{
                        locLabel.Text = "Did visit region...";
                        UIAlertView testAlert = new UIAlertView ();
                        testAlert.AddButton ("OK");
                        testAlert.Title = "Visited";
                        testAlert.Message = "Region "+e.Visit.Coordinate.Latitude.ToString()+" | "+e.Visit.Coordinate.Longitude.ToString();
                        testAlert.Show();
                    });
                };
                /* This doesn't get fired */
                locManager.RegionEntered += (o, e) => {
                    InvokeOnMainThread(()=>{
                        UIAlertView testAlert = new UIAlertView ();
                        testAlert.AddButton ("OK");
                        testAlert.Title = "Entered";
                        testAlert.Message = "Region "+e.Region.ToString();
                        testAlert.Show();
                        locLabel.Text = "Entered: "+e.Region.ToString();
                    });
                };
                /* This doesn't get fired */
                locManager.RegionLeft += (o, e) => {
                    InvokeOnMainThread(()=>{
                        UIAlertView testAlert = new UIAlertView ();
                        testAlert.AddButton ("OK");
                        testAlert.Title = "Exit";
                        testAlert.Message = "Region "+e.Region.ToString();
                        testAlert.Show();
                        locLabel.Text = "Left: "+e.Region.ToString();
                    });
                };
                locManager.StartMonitoring (region);
            }
            else
            {
            }
            // Perform any additional setup after loading the view, typically from a nib.
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            if (!UserInterfaceIdiomIsPhone) {
                openMultipeerBrowser.TouchUpInside += (sender, e) => {
                    StartMultipeerBrowser ();
                };
            } else {
                StartMultipeerAdvertiser ();
            }

            var monkeyUUID = new NSUuid (uuid);
            beaconRegion = new CLBeaconRegion (monkeyUUID, monkeyId);

            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry = true;
            beaconRegion.NotifyOnExit = true;

            if (UserInterfaceIdiomIsPhone) {

                InitPitchAndVolume ();

                locationMgr = new CLLocationManager ();

                locationMgr.RequestWhenInUseAuthorization ();

                locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => {
                    if (e.Region.Identifier == monkeyId) {
                        UILocalNotification notification = new UILocalNotification () { AlertBody = "There's a monkey hiding nearby!" };
                        UIApplication.SharedApplication.PresentLocationNotificationNow (notification);
                    }
                };

                locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                    if (e.Beacons.Length > 0) {

                        CLBeacon beacon = e.Beacons [0];
                        string message = "";

                        switch (beacon.Proximity) {
                        case CLProximity.Immediate:
                            message = "You found the monkey!";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Green;
                            break;
                        case CLProximity.Near:
                            message = "You're getting warmer";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Yellow;
                            break;
                        case CLProximity.Far:
                            message = "You're freezing cold";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Blue;
                            break;
                        case CLProximity.Unknown:
                            message = "I'm not sure how close you are to the monkey";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Gray;
                            break;
                        }

                        if (previousProximity != beacon.Proximity) {
                            Speak (message);

                            // demo send message using multipeer connectivity
                            if (beacon.Proximity == CLProximity.Immediate)
                                SendMessage ();
                        }
                        previousProximity = beacon.Proximity;
                    }
                };

                locationMgr.StartMonitoring (beaconRegion);
                locationMgr.StartRangingBeacons (beaconRegion);
            }
        }
Пример #38
0
        public bool startLookingForBeacons()
        {
            BeaconList.init ();
            Console.WriteLine ("create called");
            var beaconUUID = new NSUuid (uuid);
            var beaconRegion = new CLBeaconRegion (beaconUUID, beaconId);

            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry = true;
            beaconRegion.NotifyOnExit = true;

            locationManager = new CLLocationManager ();

            locationManager.RequestWhenInUseAuthorization ();

            locationManager.DidStartMonitoringForRegion += (object sender, CLRegionEventArgs e) => {
                locationManager.RequestState (e.Region);
            };

            locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => {
                if (e.Region.Identifier == beaconId) {
                    Console.WriteLine ("beacon region entered");
                }
            };

            locationManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => {

                switch (e.State) {
                case CLRegionState.Inside:
                    Console.WriteLine ("region state inside");
                    break;
                case CLRegionState.Outside:
                    Console.WriteLine ("region state outside");
                    break;
                case CLRegionState.Unknown:
                default:
                    Console.WriteLine ("region state unknown");
                    break;
                }
            };

            locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                if (e.Beacons.Length > 0) {
                    List<BeaconModel> beacons = new List<BeaconModel> {};
                    for (int i = 0; i < e.Beacons.Length; i++)
                    {
                        CLBeacon beacon = e.Beacons [i];
                        string proximity = "";
                        var major = (int) beacon.Major;
                        var minor = (int) beacon.Minor;
                        var accuracy = beacon.Accuracy;
                        Console.WriteLine(beacon.Major.ToString() + " " + beacon.Minor.ToString() + " " + beacon.Accuracy.ToString() );

                        switch (beacon.Proximity) {
                        case CLProximity.Immediate:
                            proximity = "Immediate";
                            break;
                        case CLProximity.Near:
                            proximity = "Near";
                            break;
                        case CLProximity.Far:
                            proximity = "Far";
                            break;
                        case CLProximity.Unknown:
                            proximity = "Unknown";
                            break;
                        }
                        BeaconModel beaconModel = new BeaconModel()
                        {
                            Major = major,
                            Minor = minor,
                            Proximity = proximity,
                            Region = e.Region.ToString(),
                            Accuracy = accuracy
                        };

            //						EventHandler<BeaconTest.onResultEventArgs> handler = onResultEvent;
            //						if (handler != null)
            //						{
            //							handler(this, new BeaconTest.onResultEventArgs{result = message});
            //						}
                        beacons.Add(beaconModel);
                    }
                    BeaconList.nearbyBeacons = BeaconList.updateList(beacons, BeaconList.nearbyBeacons, _numberOfFailedIterationsToRemove: 10);
                    BeaconList.lastUpdated = (Int32)(DateTime.UtcNow.Subtract(new  DateTime(1970,1,1,0,0,0))).TotalSeconds;
                    BeaconList.beaconsUpdated.Invoke();
                }
            };

            locationManager.StartMonitoring (beaconRegion);
            locationManager.StartRangingBeacons (beaconRegion);
            return true;
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            var monkeyUUID = new NSUuid (uuid);
            var beaconRegion = new CLBeaconRegion (monkeyUUID, monkeyId);

            beaconRegion.NotifyEntryStateOnDisplay = true;
            beaconRegion.NotifyOnEntry = true;
            beaconRegion.NotifyOnExit = true;

            if (!UserInterfaceIdiomIsPhone) {

                //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
                var power = new NSNumber (-59);
                NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData (power);
                peripheralDelegate = new BTPeripheralDelegate ();
                peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue);

                peripheralMgr.StartAdvertising (peripheralData);

            } else {

                InitPitchAndVolume ();

                locationMgr = new CLLocationManager ();

                locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => {
                    if (e.Region.Identifier == monkeyId) {
                        UILocalNotification notification = new UILocalNotification () { AlertBody = "There's a monkey hiding nearby!" };
                        UIApplication.SharedApplication.PresentLocationNotificationNow (notification);
                    }
                };

                locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                    if (e.Beacons.Length > 0) {

                        CLBeacon beacon = e.Beacons [0];
                        string message = "";

                        switch (beacon.Proximity) {
                        case CLProximity.Immediate:
                            message = "You found the monkey!";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Green;
                            break;
                        case CLProximity.Near:
                            message = "You're getting warmer";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Yellow;
                            break;
                        case CLProximity.Far:
                            message = "You're freezing cold";
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Blue;
                            break;
                        case CLProximity.Unknown:
                            message = "I'm not sure how close you are to the monkey";;
                            monkeyStatusLabel.Text = message;
                            View.BackgroundColor = UIColor.Gray;
                            break;
                        }

                        if(previousProximity != beacon.Proximity){
                            Speak (message);
                        }
                        previousProximity = beacon.Proximity;
                    }
                };

                locationMgr.StartMonitoring (beaconRegion);
                locationMgr.StartRangingBeacons (beaconRegion);
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            locationmanager = new CLLocationManager ();
              if(UIDevice.CurrentDevice.CheckSystemVersion(8, 0))
            locationmanager.RequestAlwaysAuthorization ();

              beaconUUID = new NSUuid (uuid);
              beaconRegion = new CLBeaconRegion (beaconUUID, beaconMajor, beaconMinor, beaconId);
              beaconRegion.NotifyEntryStateOnDisplay = true;
              beaconRegion.NotifyOnEntry = true;
              beaconRegion.NotifyOnExit = true;

              locationmanager.RegionEntered += (sender, e) =>
              {
            var notification = new UILocalNotification () { AlertBody = "The Xamarin beacon is close by!" };
            UIApplication.SharedApplication.CancelAllLocalNotifications();
            UIApplication.SharedApplication.PresentLocalNotificationNow (notification);

              };

              locationmanager.RegionLeft += (sender, e) =>
              {
            var notification = new UILocalNotification () { AlertBody = "The Xamarin beacon is far!" };
            UIApplication.SharedApplication.CancelAllLocalNotifications();
            UIApplication.SharedApplication.PresentLocalNotificationNow (notification);
              };

            //DidRangeBeacons
              locationmanager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) =>
              {

            if(e.Beacons.Length == 0)
              return;

            var beacon = e.Beacons[0];

            LabelBeacon.Text = "We found: " + e.Beacons.Length + " beacons" +  " " + beacon.Major + " " + beacon.Minor;
            LabelDistance.Text = beacon.Accuracy.ToString("##.000") + " " + beacon.Proximity.ToString();

            switch(beacon.Proximity)
            {
            case CLProximity.Far:
              View.BackgroundColor = UIColor.Blue;
              break;
            case CLProximity.Near:
              View.BackgroundColor = UIColor.Yellow;
              break;
            case CLProximity.Immediate:
              View.BackgroundColor = UIColor.Green;

              //locationmanager.StopRangingBeacons(beaconRegion);

              //var vc = UIStoryboard.FromName("MainStoryboard", null).InstantiateViewController("FoundViewController");
              //NavigationController.PushViewController(vc, true);
              break;
            case CLProximity.Unknown:
              return;
            }
              };

            //StartRanging
              locationmanager.StartRangingBeacons(beaconRegion);
              locationmanager.StartMonitoring (beaconRegion);
        }
Пример #41
0
        void HandleTouchDown(object sender, EventArgs e)
        {
            if (segBeacon.SelectedSegment == 0) {
                var power = new NSNumber (-59);
                NSMutableDictionary peripheralData = bRegion.GetPeripheralData (power);
                pDelegate = new BTPDelegate ();
                pManager = new CBPeripheralManager (pDelegate, DispatchQueue.DefaultGlobalQueue);

                pManager.StartAdvertising (peripheralData);
            } else {

                locManager = new CLLocationManager ();

                locManager.RegionEntered += (object s, CLRegionEventArgs ea) => {
                    if (ea.Region.Identifier == "beacon") {
                        UILocalNotification notification = new UILocalNotification () { AlertBody = "Entering beacon region!" };
                        UIApplication.SharedApplication.PresentLocationNotificationNow (notification);
                    }
                };

                locManager.DidRangeBeacons += (object s, CLRegionBeaconsRangedEventArgs ea) => {
                    if (ea.Beacons.Length > 0) {

                        CLBeacon beacon = ea.Beacons [0];
                        switch (beacon.Proximity) {
                        case CLProximity.Immediate:
                            this.View.BackgroundColor = UIColor.Green;
                            break;
                        case CLProximity.Near:
                            this.View.BackgroundColor = UIColor.Yellow;
                            break;
                        case CLProximity.Far:
                            this.View.BackgroundColor = UIColor.Red;
                            break;
                        case CLProximity.Unknown:
                            this.View.BackgroundColor = UIColor.Black;
                            break;
                        }
                    }
                };

                locManager.StartMonitoring (bRegion);
                locManager.StartRangingBeacons (bRegion);
            }
        }