Esempio n. 1
0
        //end keyboard


        public DrUViewController(IntPtr handle) : base(handle)
        {
            manager   = new CLLocationManager();
            beaconId  = new NSUuid("B9407F30-F5F8-466E-AFF9-25556B57FE6D");
            region    = new CLBeaconRegion(beaconId, "Da Reejun");
            handlePtr = handle;
        }
    void ConfigureView()
    {
      // Update the user interface for the detail item
      if (IsViewLoaded && detailItem != null)
      {
        detailDescriptionLabel.Text = detailItem.ToString();
      }

      this.Title = detailItem.Code;

      if(peripheralMgr != null)
      {
        peripheralMgr.StopAdvertising();
      }
      else
      {
        peripheralDelegate = new BTPeripheralDelegate();
        peripheralMgr = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
      }

      beaconUUID = new NSUuid(detailItem.UUID);
      beaconRegion = new CLBeaconRegion(beaconUUID, (ushort)detailItem.Major, (ushort)detailItem.Minor, beaconId);



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

      QRCode.LoadUrl(GenerateQRCodeUrl(detailItem.ToString(), QRCodeSize.Medium, QRErrorCorrection.H));
    }
Esempio n. 3
0
        public void StopScan()
        {
            if (!IsScanning)
            {
                return;
            }

            foreach (var eventHolder in _beaconEventHolderDict)
            {
                iBeacon targetBeacon = eventHolder.Value.ibeacon;

                var    uuid  = new NSUuid(targetBeacon.Uuid.ToString());
                ushort?major = targetBeacon.Major;
                ushort?minor = targetBeacon.Minor;

                CLBeaconRegion beaconRegion;

                if (major.HasValue && minor.HasValue)
                {
                    beaconRegion = new CLBeaconRegion(uuid, (ushort)major, (ushort)minor, eventHolder.Value.BeaconIdentifyStr);
                }
                else if (major.HasValue)
                {
                    beaconRegion = new CLBeaconRegion(uuid, (ushort)major, eventHolder.Value.BeaconIdentifyStr);
                }
                else
                {
                    beaconRegion = new CLBeaconRegion(uuid, eventHolder.Value.BeaconIdentifyStr);
                }

                _locationManager.StopRangingBeacons(beaconRegion);
            }

            IsScanning = false;
        }
Esempio n. 4
0
        public ProximityManager() : base()
        {
            this.region = new CLBeaconRegion(RegionUUID, RegionId);

            this.locationManager.Delegate = this;
            this.RequestAuthorization();
        }
Esempio n. 5
0
 protected BeaconRegion FromNative(CLBeaconRegion region)
 => new BeaconRegion(
     region.Identifier,
     region.ProximityUuid.FromNative(),
     region.Major?.UInt16Value,
     region.Minor?.UInt16Value
     );
Esempio n. 6
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Title                       = "Distance Demo";
            backgroundImage             = new UIImageView(UIImage.FromFile("distance_bkg"));
            backgroundImage.Frame       = UIScreen.MainScreen.Bounds;
            backgroundImage.ContentMode = UIViewContentMode.ScaleToFill;

            View.AddSubview(backgroundImage);
            View.BackgroundColor = UIColor.White;

            //var beaconImageView = new UIImageView (UIImage.FromFile ("beacon_linearnie"));
            //beaconImageView.Center = new CoreGraphics.CGPoint (View.Center.X, 100);
            //View.AddSubview (beaconImageView);


            positionDot        = new UIImageView(UIImage.FromFile("dot_image"));
            positionDot.Center = View.Center;
            View.AddSubview(positionDot);

            //Beacon manager setup.
            beaconManager = new BeaconManager();

            beaconRegion = new CLBeaconRegion(beacon.ProximityUuid, ushort.Parse(beacon.Major.ToString()), ushort.Parse(beacon.Minor.ToString()), "BeaconSample");
            beaconManager.StartRangingBeaconsInRegion(beaconRegion);
        }
Esempio n. 7
0
        public BeaconService(ISQLiteConnectionProvider sqliteConnectionProvider)
        {
            _connection = sqliteConnectionProvider.GetConnection();
            _connection.CreateTable <BeaconDataModel>();

            _beaconTransmitter = new CBPeripheralManager();
            _beaconTransmitter.StateUpdated += DidStateUpdated;

            _listOfCLBeaconRegion = new List <CLBeaconRegion>();
            _fieldRegion          = new CLBeaconRegion(new NSUuid(AppConstants.iBeaconAppUuid), "");
            _fieldRegion.NotifyEntryStateOnDisplay = true;
            _fieldRegion.NotifyOnEntry             = true;
            _fieldRegion.NotifyOnExit = true;

            // Monitoring
            _locationManager = new CLLocationManager();
            if (CLLocationManager.LocationServicesEnabled)
            {
                _locationManager.Delegate = this;
                _locationManager.PausesLocationUpdatesAutomatically = false;
                _locationManager.ShowsBackgroundLocationIndicator   = true;
                _locationManager.DistanceFilter = 1.0;
                _locationManager.AllowsBackgroundLocationUpdates = true;
                _locationManager.DidRangeBeacons      += DidRangeBeconsInRegionComplete;
                _locationManager.AuthorizationChanged += HandleAuthorizationChanged;
                _locationManager.RequestAlwaysAuthorization();
            }
        }
Esempio n. 8
0
 public LocationDelegate()
 {
     // 領域定義の初期化
     研究室領域 = new CLBeaconRegion(new NSUuid(RegionList.研究室.Uuid), (ushort)RegionList.研究室.Major, (ushort)RegionList.研究室.Minor, RegionList.研究室.Identifier);
     学内領域  = RegionList.CampusAllRegions
             .Select(r => new CLCircularRegion(new CLLocationCoordinate2D(r.Latitude, r.Longitude), r.Radius, r.Identifier));
 }
Esempio n. 9
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);
        }
        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}");
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            Title = "Notification Demo";
            beaconManager = new BeaconManager ();
            beaconRegion = new CLBeaconRegion (Beacon.ProximityUuid, ushort.Parse(Beacon.Major.ToString()), ushort.Parse(Beacon.Minor.ToString()), "BeaconSample");

            beaconRegion.NotifyOnEntry = enterSwitch.On;
            beaconRegion.NotifyOnExit = exitSwitch.On;

            enterSwitch.ValueChanged += HandleValueChanged;
            exitSwitch.ValueChanged += HandleValueChanged;

            beaconManager.StartMonitoringForRegion (beaconRegion);

            beaconManager.ExitedRegion += (sender, e) =>
            {
                var notification = new UILocalNotification();
                notification.AlertBody = "Exit region notification";
                UIApplication.SharedApplication.PresentLocalNotificationNow(notification);
            };

            beaconManager.EnteredRegion += (sender, e) =>
            {
                var notification = new UILocalNotification();
                notification.AlertBody = "Enter region notification";
                UIApplication.SharedApplication.PresentLocalNotificationNow(notification);
            };
        }
Esempio n. 12
0
        public static CLBeaconRegion ToNative(this BeaconRegion region)
        {
            var            uuid = ToNsUuid(region);
            CLBeaconRegion native;

            if (region.Major > 0 && region.Minor > 0)
            {
                native = new CLBeaconRegion(uuid, region.Major.Value, region.Minor.Value, region.Identifier);
            }

            else if (region.Major > 0)
            {
                native = new CLBeaconRegion(uuid, region.Major.Value, region.Identifier);
            }

            else
            {
                native = new CLBeaconRegion(uuid, region.Identifier);
            }

            //native.NotifyEntryStateOnDisplay = true;
            native.NotifyOnEntry = region.NotifyOnEntry;
            native.NotifyOnExit  = region.NotifyOnExit;

            return(native);
        }
        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();
        }
Esempio n. 14
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);
                }
            }
        }
        public BeaconContent GetBeaconContent(CLBeacon beacon, CLBeaconRegion region)
        {
            BeaconContent[] regions;
            bool            show = false;

            regions = _testData.GetBeaconContent();

            var r = (from h in regions
                     where h.Major == beacon.Major.ToString() && h.Minor == beacon.Minor.ToString() && h.ProximityUuid.ToString() == beacon.ProximityUuid.AsString()
                     select h).FirstOrDefault();

            //Only needed for testing
            if (r != null)
            {
                r.Proximity = beacon.Proximity;
                r.Rssi      = beacon.Rssi;
                r.Accuracy  = beacon.Accuracy;
            }


            if (r != null)
            {
                show = ShouldShowContent(r.ContentId);
            }

            return((show) ? r as BeaconContent : null);
        }
Esempio n. 16
0
        public CocoaBeaconProvider(CLBeaconRegion beaconRegion)
        {
            Debug.WriteLine("constructor()", LogTag);

            if (!CLLocationManager.LocationServicesEnabled)
            {
                Debug.WriteLine("Location services disabled, my bad.", LogTag);
                return;
            }

            try
            {
                CLBeaconRegion oldRegion = new CLBeaconRegion(beaconRegion.Uuid, beaconRegion.Major.UInt16Value, beaconRegion.Minor.UInt16Value, "TPMS");

                _locationManager.StopMonitoring(oldRegion);
            }
            catch (Exception)
            {
            }

            _locationManagerDelegate = new UniversalBeaconLocationManagerDelegate(this);

            _locationManager          = new CLLocationManager();
            _locationManager.Delegate = _locationManagerDelegate;

            _clBeaconRegion = beaconRegion;
        }
Esempio n. 17
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Title = "Proximity Demo";

            View.BackgroundColor    = UIColor.White;
            zoneLabel               = new UILabel(new CGRect(0, 100, View.Frame.Size.Width, 40));
            zoneLabel.TextAlignment = UITextAlignment.Center;
            View.AddSubview(zoneLabel);


            imageView             = new UIImageView(new CGRect(0, 64, View.Frame.Size.Width, View.Frame.Size.Height - 64));
            imageView.ContentMode = UIViewContentMode.Center;
            View.AddSubview(imageView);

            //beacon setup
            beaconManager = new BeaconManager();
            beaconRegion  = new CLBeaconRegion(beacon.ProximityUuid, ushort.Parse(beacon.Major.ToString()), ushort.Parse(beacon.Minor.ToString()), "RegionIdentifier");

            beaconManager.StartRangingBeaconsInRegion(beaconRegion);

            beaconManager.RangedBeacons += (sender, e) =>
            {
                if (e.Beacons.Length == 0)
                {
                    return;
                }

                zoneLabel.Text  = TextForProximity(e.Beacons[0].Proximity);
                imageView.Image = ImageForProximity(e.Beacons[0].Proximity);
            };
        }
Esempio n. 18
0
        public void StartScan()
        {
            if (!BluetoothIsAvailableOnThisDevice())
            {
                throw new Exception("This device does not support Bluetooth.");
            }

            if (!CLLocationManager.RegionMonitoringEnabled)
            {
                throw new Exception("Bluetooth service on this device is turned off.");
            }

            if (IsScanning)
            {
                return;
            }

            _detectedBeaconDict = new Dictionary <string, iBeacon>();

            foreach (var eventHolder in _beaconEventHolderDict)
            {
                var uuid         = new NSUuid(eventHolder.Value.ibeacon.Uuid.ToString());
                var beaconRegion = new CLBeaconRegion(uuid,
                                                      eventHolder.Value.ibeacon.Major,
                                                      eventHolder.Value.ibeacon.Minor,
                                                      eventHolder.Value.BeaconIdentifyStr);

                _locationManager.StartRangingBeacons(beaconRegion);
            }

            IsScanning = true;
        }
Esempio n. 19
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);
        }
Esempio n. 20
0
        void InitializeBeacons()
        {
            StopRanging();

            if (viewModel.Quest.Major >= 0)
            {
                beaconRegion = new CLBeaconRegion(new NSUuid(viewModel.UUID), (ushort)viewModel.Quest.Major, BeaconId);
                beaconRegion.NotifyOnExit  = true;
                beaconRegion.NotifyOnEntry = true;
            }

            InvokeOnMainThread(() =>
            {
                Beacon1.Image  = Beacon2.Image = Beacon3.Image = undiscoveredBeacon;
                Beacon1.Hidden = Beacon2.Hidden = Beacon3.Hidden = true;
                SetBeaconText(false);
                for (int i = 0; i < viewModel.Quest.Beacons.Count; i++)
                {
                    beacons[i].Hidden = false;
                }

                UpdateBeacons();
                MainImage.LoadUrl(viewModel.Quest.Clue.Image);
                MainText.Text = viewModel.Quest.Clue.Message;
            });
            StartRanging();
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            Title         = "Notification Demo";
            beaconManager = new BeaconManager();
            beaconRegion  = new CLBeaconRegion(Beacon.ProximityUuid, ushort.Parse(Beacon.Major.ToString()), ushort.Parse(Beacon.Minor.ToString()), "BeaconSample");

            beaconRegion.NotifyOnEntry = enterSwitch.On;
            beaconRegion.NotifyOnExit  = exitSwitch.On;

            enterSwitch.ValueChanged += HandleValueChanged;
            exitSwitch.ValueChanged  += HandleValueChanged;

            beaconManager.StartMonitoring(beaconRegion);

            beaconManager.ExitedRegion += (sender, e) =>
            {
                var notification = new UILocalNotification();
                notification.AlertBody = "Exit region notification";
                UIApplication.SharedApplication.PresentLocalNotificationNow(notification);
            };

            beaconManager.EnteredRegion += (sender, e) =>
            {
                var notification = new UILocalNotification();
                notification.AlertBody = "Enter region notification";
                UIApplication.SharedApplication.PresentLocalNotificationNow(notification);
            };
        }
Esempio n. 22
0
        protected CLBeaconRegion ToNative(BeaconRegion region)
        {
            if (region.Uuid == null)
            {
                throw new ArgumentException("You must pass a UUID for the Beacon Region");
            }

            var            uuid   = region.Uuid.ToNSUuid();
            CLBeaconRegion native = null;

            if (region.Major > 0 && region.Minor > 0)
            {
                native = new CLBeaconRegion(uuid, region.Major.Value, region.Minor.Value, region.Identifier);
            }

            else if (region.Major > 0)
            {
                native = new CLBeaconRegion(uuid, region.Major.Value, region.Identifier);
            }

            else
            {
                native = new CLBeaconRegion(uuid, region.Identifier);
            }

            //native.NotifyEntryStateOnDisplay = true;
            native.NotifyOnEntry = true;
            native.NotifyOnExit  = true;

            return(native);
        }
Esempio n. 23
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);
        }
Esempio n. 24
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");
        }
Esempio n. 25
0
        public BeaconService()
        {
            _connection = DependencyService.Resolve <SQLiteConnectionProvider>().GetConnection();
            _connection.CreateTable <BeaconDataModel>();
            _userDataService = DependencyService.Resolve <UserDataService>();
            _userData        = _userDataService.Get();
            _httpDataService = DependencyService.Resolve <HttpDataService>();
            _uploadTimer     = new MinutesTimer(_userData.GetJumpHashTimeDifference());
            _uploadTimer.Start();
            _uploadTimer.TimeOutEvent += TimerUpload;

            _beaconTransmitter = new CBPeripheralManager();
            _beaconTransmitter.AdvertisingStarted += DidAdvertisingStarted;
            _beaconTransmitter.StateUpdated       += DidStateUpdated;

            _listOfCLBeaconRegion = new List <CLBeaconRegion>();
            _fieldRegion          = new CLBeaconRegion(new NSUuid(AppConstants.iBeaconAppUuid), "");
            _fieldRegion.NotifyEntryStateOnDisplay = true;
            _fieldRegion.NotifyOnEntry             = true;
            _fieldRegion.NotifyOnExit = true;

            // Monitoring
            _beaconManager = new CLLocationManager();
            _beaconManager.DidDetermineState += DetermineStateForRegionComplete;
            _beaconManager.RegionEntered     += EnterRegionComplete;
            _beaconManager.RegionLeft        += ExitRegionComplete;
            _beaconManager.PausesLocationUpdatesAutomatically = false;
            _beaconManager.AllowsBackgroundLocationUpdates    = true;
            _beaconManager.ShowsBackgroundLocationIndicator   = true;


            _beaconManager.DidRangeBeacons      += DidRangeBeconsInRegionComplete;
            _beaconManager.AuthorizationChanged += HandleAuthorizationChanged;
        }
Esempio n. 26
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);
        }
        void ConfigureView()
        {
            // Update the user interface for the detail item
            if (IsViewLoaded && detailItem != null)
            {
                detailDescriptionLabel.Text = detailItem.ToString();
            }

            this.Title = detailItem.Code;

            if (peripheralMgr != null)
            {
                peripheralMgr.StopAdvertising();
            }
            else
            {
                peripheralDelegate = new BTPeripheralDelegate();
                peripheralMgr      = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
            }

            beaconUUID   = new NSUuid(detailItem.UUID);
            beaconRegion = new CLBeaconRegion(beaconUUID, (ushort)detailItem.Major, (ushort)detailItem.Minor, beaconId);



            //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
            var power = new NSNumber(-59);

            peripheralData = beaconRegion.GetPeripheralData(power);
            peripheralMgr.StartAdvertising(peripheralData);

            QRCode.LoadUrl(GenerateQRCodeUrl(detailItem.ToString(), QRCodeSize.Medium, QRErrorCorrection.H));
        }
        protected virtual CLBeaconRegion ToNative(BeaconRegion region)
        {
            var            uuid   = new NSUuid(region.Uuid);
            CLBeaconRegion native = null;

            if (region.Major > 0 && region.Minor > 0)
            {
                native = new CLBeaconRegion(uuid, region.Major.Value, region.Minor.Value, region.Identifier);
            }

            else if (region.Major > 0)
            {
                native = new CLBeaconRegion(uuid, region.Major.Value, region.Identifier);
            }

            else
            {
                native = new CLBeaconRegion(uuid, region.Identifier);
            }

            native.NotifyEntryStateOnDisplay = true;
            native.NotifyOnEntry             = true;
            native.NotifyOnExit = true;

            return(native);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            Title = "Proximity Demo";

            View.BackgroundColor = UIColor.White;
            zoneLabel = new UILabel (new CGRect (0, 100, View.Frame.Size.Width, 40));
            zoneLabel.TextAlignment = UITextAlignment.Center;
            View.AddSubview (zoneLabel);

            imageView = new UIImageView (new CGRect (0, 64, View.Frame.Size.Width, View.Frame.Size.Height - 64));
            imageView.ContentMode = UIViewContentMode.Center;
            View.AddSubview (imageView);

            //beacon setup
            beaconManager = new BeaconManager ();
            beaconRegion = new CLBeaconRegion (beacon.ProximityUuid,ushort.Parse( beacon.Major.ToString()), ushort.Parse(beacon.Minor.ToString()), "RegionIdentifier");

            beaconManager.StartRangingBeaconsInRegion (beaconRegion);

            beaconManager.RangedBeacons += (sender, e) =>
            {
                if(e.Beacons.Length == 0 )
                    return;

                zoneLabel.Text = TextForProximity(e.Beacons[0].Proximity);
                imageView.Image = ImageForProximity(e.Beacons[0].Proximity);
            };
        }
        private void SetupBeaconRanging()
        {
            locationManager = new CLLocationManager();
            beacons         = new List <BeaconItem> ();

            var rUuid = new NSUuid(roximityUuid);

            rBeaconRegion = new CLBeaconRegion(rUuid, roximityBeaconId);

            var eUuid = new NSUuid(estimoteUuid);

            eBeaconRegion = new CLBeaconRegion(eUuid, estimoteBeaconId);

            rBeaconRegion.NotifyEntryStateOnDisplay = true;
            rBeaconRegion.NotifyOnEntry             = true;
            rBeaconRegion.NotifyOnExit = true;

            eBeaconRegion.NotifyEntryStateOnDisplay = true;
            eBeaconRegion.NotifyOnEntry             = true;
            eBeaconRegion.NotifyOnExit = true;

            locationManager.RegionEntered     += HandleRegionEntered;
            locationManager.RegionLeft        += HandleRegionLeft;
            locationManager.DidDetermineState += HandleDidDetermineState;
            locationManager.DidRangeBeacons   += HandleDidRangeBeacons;
        }
Esempio n. 31
0
        public override void ViewDidLoad()
        {
            this.View.BackgroundColor = UIColor.LightGray;

            guid = new NSUuid ("c5cf54e0-6dd8-45e9-91a3-a8cda2f41120");
            bRegion = new CLBeaconRegion (guid, "beacon");

            bRegion.NotifyEntryStateOnDisplay = true;
            bRegion.NotifyOnEntry = true;
            bRegion.NotifyOnExit = true;

            base.ViewDidLoad ();

            segBeacon = new UISegmentedControl (new string[] { "Beacon", "Finder" });
            segBeacon.Frame = new RectangleF (20, 50, this.View.Bounds.Width - 40, 50);
            segBeacon.SelectedSegment = 0;

            button = new UIButton (UIButtonType.RoundedRect);
            button.SetTitle ("Start!", UIControlState.Normal);
            button.Frame = new RectangleF (50, 150, this.View.Bounds.Width - 100, 30);

            button.TouchDown += HandleTouchDown;
            this.View.AddSubview (segBeacon);
            this.View.AddSubview (button);
        }
Esempio n. 32
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);
            CLBeaconRegion region = (CLBeaconRegion)locationManger.MonitoredRegions.AnyObject;

            enabled = (region != null);
            if (enabled)
            {
                uuid            = region.ProximityUuid;
                major           = region.Major;
                minor           = region.Minor;
                notifyOnEntry   = region.NotifyOnEntry;
                notifyOnExit    = region.NotifyOnExit;
                notifyOnDisplay = region.NotifyEntryStateOnDisplay;
            }
            else
            {
                uuid            = Defaults.DefaultProximityUuid;
                major           = minor = null;
                notifyOnEntry   = true;
                notifyOnExit    = true;
                notifyOnDisplay = false;
            }

            majorTextField.Text = major == null ? String.Empty : major.Int32Value.ToString();
            minorTextField.Text = minor == null ? String.Empty : minor.Int32Value.ToString();

            uuidTextField.Text       = uuid.AsString();
            enabledSwitch.On         = enabled;
            notifyOnEntrySwitch.On   = notifyOnEntry;
            notifyOnExitSwitch.On    = notifyOnExit;
            notifyOnDisplaySwitch.On = notifyOnDisplay;
        }
Esempio n. 33
0
        public override void RowSelected(UITableView tableView, NSIndexPath indexPath)
        {
            if (inProgress)
            {
                return;
            }

            CLBeacon       beacon = beacons [GetNonEmptySection(indexPath.Section)] [indexPath.Row];
            CLBeaconRegion region = Helpers.CreateRegion(beacon.ProximityUuid, beacon.Major, beacon.Minor);

            if (region == null)
            {
                return;
            }

            // We can stop ranging to display beacons available for calibration.
            StopRangingAllRegions();
            // And we'll start the calibration process.
            calculator = new CalibrationCalculator(region, CompletionHandler);
            calculator.PerformCalibration((sender, e) => {
                progressBar.SetProgress(e.PercentComplete, true);
            });

            progressBar.Progress = 0.0f;
            inProgress           = true;
            TableView.ReloadData();
        }
Esempio n. 34
0
 static Region()
 {
     beaconRegion = new CLBeaconRegion(new NSUuid(Globals.BroadcastUUID), Globals.BeaconRegion);
     beaconRegion.NotifyEntryStateOnDisplay = true;
     beaconRegion.NotifyOnEntry             = true;
     beaconRegion.NotifyOnExit = true;
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            Title = "Distance Demo";
            backgroundImage = new UIImageView(UIImage.FromFile ("distance_bkg"));
            backgroundImage.Frame = UIScreen.MainScreen.Bounds;
            backgroundImage.ContentMode = UIViewContentMode.ScaleToFill;

            View.AddSubview (backgroundImage);
            View.BackgroundColor = UIColor.White;

            //var beaconImageView = new UIImageView (UIImage.FromFile ("beacon_linearnie"));
            //beaconImageView.Center = new CoreGraphics.CGPoint (View.Center.X, 100);
            //View.AddSubview (beaconImageView);

            positionDot = new UIImageView (UIImage.FromFile ("dot_image"));
            positionDot.Center = View.Center;
            View.AddSubview (positionDot);

            //Beacon manager setup.
            beaconManager = new BeaconManager ();

            beaconRegion = new CLBeaconRegion (beacon.ProximityUuid, ushort.Parse( beacon.Major.ToString()), ushort.Parse(beacon.Minor.ToString()), "BeaconSample");
            beaconManager.StartRangingBeaconsInRegion(beaconRegion);
        }
		public override void ViewDidAppear (bool animated)
		{
			base.ViewDidLoad ();
			this.Title = "Select Beacon";
			beaconManager = new BeaconManager ();
			beaconManager.ReturnAllRangedBeaconsAtOnce = true;
			region = new CLBeaconRegion (AppDelegate.BeaconUUID, "BeaconSample");
		}
		public RangingVC (IntPtr handle) : base (handle)
		{
			SetUpHue ();



			//set up sqlite db
			var documents = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
			_pathToDatabase = Path.Combine (documents, "db_sqlite-net.db");

			region = new CLBeaconRegion (AppDelegate.BeaconUUID, "BeaconSample");//ushort.Parse ("26547"), ushort.Parse ("56644"),
			region.NotifyOnEntry = true;
			region.NotifyOnExit = true;

			locationManager = new CLLocationManager ();
			locationManager.RequestWhenInUseAuthorization ();

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

					CLBeacon beacon = e.Beacons [0];

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

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

			};

			locationManager.StartRangingBeacons (region);

			var db = new SQLite.SQLiteConnection (_pathToDatabase);
			var bridgeIp = db.Table<HueBridge> ().ToArray ();
			client = new LocalHueClient (bridgeIp [0].HueBridgeIpAddress);
			client.Initialize ("pooberry");
		}
Esempio n. 38
0
		public BeaconService ()
		{
			_locationManager = new CLLocationManager ();
			_locationManager.Delegate = this;

			_beacons = new List<BeaconDevice> ();

			_allBeaconsRegion = new CLBeaconRegion (new NSUuid (uuid), "All Beacons Region");

			_sync = new object ();
		}
		public void BeaconsRanged (CLBeacon[] beacons, CLBeaconRegion region)
		{
			foreach (var beacon in beacons) {
				Beacons.RemoveAll (obj => beacon.Major == obj.Major && beacon.Minor == obj.Minor);
				Beacons.Add (beacon);
			}

			Beacons = Beacons.OrderBy (BeaconManager.OrderByProximity).ToList ();

			TableView.ReloadData ();
		}
		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);
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            // Perform any additional setup after loading the view, typically from a nib.

            _locationManager = new CLLocationManager();
            _locationManager.AuthorizationChanged += LocationManagerAuthorizationChanged;
            _locationManager.DidRangeBeacons += LocationManagerDidRangeBeacons;

            _locationManager.RequestAlwaysAuthorization();

            _region = new CLBeaconRegion(new NSUuid("18E1FDEA-15E6-425E-B88C-2642B8F3C378"), "MyRegion");
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			Title = "Ranging";

			// Populate the regions we will range once.
			rangedRegions = new List<CLBeaconRegion> ();

			foreach (NSUuid uuid in Defaults.SupportedProximityUuids) {
				CLBeaconRegion region = new CLBeaconRegion (uuid, uuid.AsString ());
				rangedRegions.Add (region);
			}
		}
Esempio n. 43
0
        public static void RegisterBeaconRegion(string uuid, ushort major, string regionId)
        {
            var NSUUID = new NSUuid (uuid);
            var beaconRegion = new CLBeaconRegion (NSUUID, major, regionId);

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

            locationManager.StartMonitoring (beaconRegion);
            locationManager.StartRangingBeacons (beaconRegion);

            beaconRegions.Add (beaconRegion);
        }
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear (animated);

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

            //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away
            var power = new NSNumber (-59);

            var peripheralData = beaconRegion.GetPeripheralData (power);
            peripheralDelegate = new BTPeripheralDelegate ();
            peripheralManager.StartAdvertising (peripheralData);
        }
Esempio n. 45
0
		public void AddBeaconToMonitoring (BeaconDevice beacon)
		{
			lock (_sync) {
				var monitored = _locationManager.MonitoredRegions;
				if (monitored.All (m => (m as CLBeaconRegion)?.Identifier != beacon.DeviceId)) {
					var beaconRegion = new CLBeaconRegion (new NSUuid (beacon.Uuid), (ushort)beacon.Major, (ushort)beacon.Minor, beacon.DeviceId);
					beaconRegion.NotifyOnEntry = true;
					beaconRegion.NotifyOnExit = true;

					_locationManager.StartMonitoring (beaconRegion);
				}
				_beacons.Add (beacon);
			}
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            Title = "Notification Demo";
            beaconManager = new BeaconManager ();
            beaconRegion = new CLBeaconRegion (Beacon.ProximityUuid, ushort.Parse(Beacon.Major.ToString()), ushort.Parse(Beacon.Minor.ToString()), "BeaconSample");

            beaconRegion.NotifyOnEntry = enterSwitch.On;
            beaconRegion.NotifyOnExit = exitSwitch.On;

            enterSwitch.ValueChanged += HandleValueChanged;
            exitSwitch.ValueChanged += HandleValueChanged;

            beaconManager.StartMonitoringForRegion (beaconRegion);
        }
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			beaconUUID = new NSUuid (uuid);
			beaconRegion = new CLBeaconRegion (beaconUUID, beaconMajor, beaconMinor, beaconId);



			//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);
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			Title = "Calibration";

			progressBar = new UIProgressView (UIProgressViewStyle.Default) {
				AutoresizingMask = UIViewAutoresizing.FlexibleMargins
			};

			// Populate the regions for the beacons we're interested in calibrating.
			rangedRegions = new List<CLBeaconRegion> ();

			foreach (NSUuid uuid in Defaults.SupportedProximityUuids) {
				var region = new CLBeaconRegion (uuid, uuid.AsString ());
				rangedRegions.Add (region);
			}
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			this.Title = "Select Beacon";
			
            utilityManager = new UtilityManager ();
            beaconManager = new BeaconManager ();
			beaconManager.ReturnAllRangedBeaconsAtOnce = true;
            region = new CLBeaconRegion (AppDelegate.BeaconUUID, "BeaconSample");

            beaconManager.AuthorizationStatusChanged += (sender, e) => 
                StartRangingBeacons ();
            beaconManager.RangedBeacons += (sender, e) => 
            {
                beacons = e.Beacons;
                TableView.ReloadData();
            };
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            var uuid = new NSUuid ("A1F30FF0-0A9F-4DE0-90DA-95F88164942E");
            var beaconId = "iOSBeacon";
            var beaconRegion = new CLBeaconRegion (uuid, beaconId) {
                NotifyEntryStateOnDisplay = true,
                NotifyOnEntry = true,
                NotifyOnExit = true
            };

            var peripheralData = beaconRegion.GetPeripheralData (new NSNumber (-59));

            peripheralDelegate = new BTPeripheralDelegate ();
            peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue);
            peripheralMgr.StartAdvertising (peripheralData);
        }
		public CalibrationCalculator (CLBeaconRegion region, EventHandler<CalibrationCompletedEventArgs> handler)
		{
			this.region = region;
			rangedBeacons = new List<CLBeacon[]> ();
			CalibrationCompletionHandler = handler;

			locationManager = new CLLocationManager ();
			locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
				rangedBeacons.Add (e.Beacons);
				var progress = ProgressHandler;
				if (progress != null) {
					DispatchQueue.MainQueue.DispatchAsync (delegate {
						percentComplete += 1.0f / 20.0f;
						progress (this, new CalibrationProgressEventArgs () { PercentComplete = percentComplete });
					});
				}
			};
		}
Esempio n. 52
0
        public override bool FinishedLaunching(UIApplication application, NSDictionary launchOptions)
        {
            var userNotificationSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert, new NSSet());
            UIApplication.SharedApplication.RegisterUserNotificationSettings(userNotificationSettings);

            _beaconRegion = new CLBeaconRegion(new NSUuid("17BFFC6C-A5DF-4198-ADAE-73D616A50009"), "My Region");
            _beaconRegion.NotifyOnEntry = true;
            _beaconRegion.NotifyOnExit = true;

            _beaconManager = new CLLocationManager();

            _beaconManager.AuthorizationChanged += BeaconManagerAuthorizationStatusChanged;
            _beaconManager.RegionEntered += BeaconManagerEnteredRegion;
            _beaconManager.RegionLeft += BeaconManagerExitedRegion;
            _beaconManager.RequestAlwaysAuthorization();

            return true;
        }
Esempio n. 53
0
        public string StartListening(List<IBBeacon> beacons)
        {
            foreach (IBBeacon b in beacons)
            {
                CLBeaconRegion r = new CLBeaconRegion(
                    b.ProximityUuid == null ? new NSUuid("") : new NSUuid(b.ProximityUuid),
                    b.BeaconId);

                r.NotifyEntryStateOnDisplay = true;
                r.NotifyOnEntry = true;
                r.NotifyOnExit = true;

                locationMgr.StartMonitoring(r);
                locationMgr.StartRangingBeacons(r);
                Regions.Add(r);
            }

            return "Success";
        }
        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

            var userNotificationSettings = UIUserNotificationSettings.GetSettingsForTypes(UIUserNotificationType.Alert, new NSSet());
            UIApplication.SharedApplication.RegisterUserNotificationSettings(userNotificationSettings);

            _locationManager = new CLLocationManager();
            _locationManager.AuthorizationChanged += LocationManagerAuthorizationChanged;
            _locationManager.RegionEntered += LocationManagerRegionEntered;
            _locationManager.RegionLeft += LocationManagerRegionLeft;

            _locationManager.RequestAlwaysAuthorization();

            _region = new CLBeaconRegion(new NSUuid("18E1FDEA-15E6-425E-B88C-2642B8F3C378"), "MyRegion");

            return true;
        }
Esempio n. 55
0
        public void StartListeningForBeacons()
        {
            beaconRegion = new CLBeaconRegion (beaconUUID, "0");
            locationManager = new CLLocationManager ();

            locationManager.Failed += (object sender, NSErrorEventArgs e) => {
                Console.WriteLine ("Failure " + e.ToString ());
            };

            locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs args) => {
                List<Beacon> foundBeacons = new List<Beacon> ();

                foreach (CLBeacon clBeacon in args.Beacons) {
                    foundBeacons.Add(new Beacon() { Major = clBeacon.Major.Int32Value, Minor = clBeacon.Minor.Int32Value, Proximity = clBeacon.Proximity, Accuracy = clBeacon.Accuracy });
                }
                this.BeaconsFound (this, new BeaconFoundEventArgs (foundBeacons));
            };
            locationManager.StartRangingBeacons (beaconRegion);
            locationManager.StartUpdatingLocation ();
        }
        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);
        }
Esempio n. 57
0
		private void SetupBeaconRanging ()
		{
			locationManager = new CLLocationManager ();
			beacons = new List<BeaconItem> ();

			var rUuid = new NSUuid (roximityUuid);
			rBeaconRegion = new CLBeaconRegion (rUuid, roximityBeaconId);

			var eUuid = new NSUuid (estimoteUuid);
			eBeaconRegion = new CLBeaconRegion (eUuid, estimoteBeaconId);

			rBeaconRegion.NotifyEntryStateOnDisplay = true;
			rBeaconRegion.NotifyOnEntry = true;
			rBeaconRegion.NotifyOnExit = true;

			eBeaconRegion.NotifyEntryStateOnDisplay = true;
			eBeaconRegion.NotifyOnEntry = true;
			eBeaconRegion.NotifyOnExit = true;

			locationManager.RegionEntered += HandleRegionEntered;
			locationManager.RegionLeft += HandleRegionLeft;
			locationManager.DidDetermineState += HandleDidDetermineState;
			locationManager.DidRangeBeacons += HandleDidRangeBeacons;
		}
Esempio n. 58
0
        public void StartScanning(int milliSecond = 0)
        {
            BeaconManager = new BeaconManager();
            BeaconManager.ReturnAllRangedBeaconsAtOnce = true;
            BeaconRegion = new CLBeaconRegion(new NSUuid(App.Self.BEACON_ID), "beacons");
            CheckForBluetooth();
            BeaconRegion.NotifyEntryStateOnDisplay = true;
            BeaconRegion.NotifyOnEntry = true;
            BeaconRegion.NotifyOnExit = true;

            AppDelegate.Self.LocationManager.DidStartMonitoringForRegion += (object sender, CLRegionEventArgs e) =>
            AppDelegate.Self.LocationManager.RequestState(e.Region);

            CloudManager = new CloudManager();

            try
            {
                var beacons = CloudManager.FetchEstimoteBeaconsAsync().ContinueWith(t =>
                    {
                        if (t.IsCompleted)
                        {
                            var list = t.Result;
                            foreach (var b in list)
                            {
                                App.Self.Beacons.Add(new BeaconData
                                    {
                                        MacAddress = b.MacAddress.ToString(),
                                        Major = (int)b.Major, MeasuredPower = (int)b.Power, Minor = (int)b.Minor,
                                        Name = b.Name, /*Rssi = e.Region.Rssi,*/ ProximityUUID = b.ToString(),
                                        Region = new RegionData
                                        {
                                            Major = (int)b.Major, Minor = (int)b.Minor,
                                            Identifier = b.Name, ProximityUUID = b.ProximityUUID.ToString()
                                        }
                                    });
                            }
                        }
                    }).ConfigureAwait(true);
            }
            catch
            {
                new UIAlertView("Error", "Unable to fetch cloud beacons, ensure you have set Config in AppDelegate", null, "OK").Show();
            }

            AppDelegate.Self.LocationManager.RegionEntered += (object sender, CLRegionEventArgs e) =>
            {
                if (e.Region.Identifier == App.Self.BEACON_ID)
                {
                    Console.WriteLine("beacon region entered");
                }
            };

            AppDelegate.Self.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;
                }
            };

            AppDelegate.Self.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;
                }
            };

            //if (BeaconManager.IsAuthorizedForMonitoring && BeaconManager.IsAuthorizedForRanging)
            //{
            BeaconRegion = new CLBeaconRegion(new NSUuid(App.Self.BEACON_ID), "BeaconSample");
            BeaconManager.RangedBeacons += (object sender, RangedBeaconsEventArgs e) =>
            {
                foreach (var beacon in App.Self.Beacons)
                {
                    var found = e.Beacons.FirstOrDefault(t => (int)t.Major == beacon.Major);
                    var idx = e.Beacons.ToList().IndexOf(found);
                    if (found != null)
                    {
                        if (idx < App.Self.Beacons.Count)
                        {
                            App.Self.Beacons[idx].Rssi = (int)found.Rssi;
                        }
                    }
                }
            };

            BeaconManager.EnteredRegion += (sender, e) =>
            {
                if (App.Self.Beacons.Count != 0)
                {
                    var exists = (from beacon in App.Self.Beacons
                                                 where beacon.Major == (int)e.Region.Major
                                                 select beacon).FirstOrDefault();
                    //var exists = App.Self.Beacons.FirstOrDefault(t => t.Major == e.Beacons.FirstOrDefault(w => w.Major));
                    if (exists == null)
                        App.Self.Beacons.Add(exists);
                    else
                    {
                        var index = App.Self.Beacons.IndexOf(exists);
                        if (index != -1)
                            App.Self.Beacons[index] = exists;
                    }
                }
                else
                {
                    App.Self.Beacons.Add(new BeaconData
                        {
                            /*MacAddress = beacon.MacAddress.ToString(),*/
                            Major = (int)e.Region.Major, MeasuredPower = (int)e.Region.Radius, Minor = (int)e.Region.Minor,
                            /*Name = beacon.Name, Rssi = e.Region.Rssi,*/ ProximityUUID = e.Region.ProximityUuid.ToString(),
                            Region = new RegionData
                            {
                                Major = (int)e.Region.Major, Minor = (int)e.Region.Minor,
                                Identifier = e.Region.Identifier, ProximityUUID = e.Region.ProximityUuid.ToString()
                            }
                        });
                }
            };

            BeaconManager.ExitedRegion += (sender, e) =>
            {
                if (App.Self.Beacons.Count != 0)
                {
                    var exists = (from b in App.Self.Beacons
                                                 let reg = b.Region
                                                 where reg.Identifier == e.Region.Identifier
                                                 select reg).FirstOrDefault();
                    if (exists != null)
                    {
                        var index = App.Self.Beacons.IndexOf(App.Self.Beacons.FirstOrDefault(t => t.Region.Major == (int)e.Region.Major));
                        App.Self.Beacons.RemoveAt(index);
                    }
                }
            };
            //}
        }
Esempio n. 59
0
    void Start()
    {
        if (CoreXT.IsDevice) {
            // subscribes to events

            beaconRegion = new CLBeaconRegion(new NSUUID(proximityUUID), beaconID);

            // only works if Unity is in the background.  But if Unity is killed, it doesn't work.
            beaconRegion.notifyEntryStateOnDisplay = true;
            beaconRegion.notifyOnEntry = true;
            beaconRegion.notifyOnExit = true;
        }
    }
Esempio n. 60
0
		public override void DidRangeBeacons (CLLocationManager manager, CLBeacon[] beacons, CLBeaconRegion region)
		{
			CLBeacon beacon;
			lock (_sync) {
				//we need uniq beacon which is close then 5sm
				beacon = beacons.FirstOrDefault (b => _beacons.All (eb => eb.Major != b.Major.Int32Value || eb.Minor != b.Minor.Int32Value) && b.Proximity == CLProximity.Immediate && b.Accuracy < NearestDistance);
				if (beacon == null)
					return;

				System.Diagnostics.Debug.WriteLine ("FindBeacon " + beacon);

				//We found one - no need to find again as we will find it again in some seconds
				StopFindNearest ();
			}

			var nearestBeacon = new BeaconDevice {
				Uuid = beacon.ProximityUuid.AsString (),
				Major = beacon.Major.Int32Value,
				Minor = beacon.Minor.Int32Value
			};
			NearestFound (this, new BeaconEventArgs { BeaconDevice = nearestBeacon });
		}