void LocationManagerDidRangeBeacons(object sender, CLRegionBeaconsRangedEventArgs e)
        {
            CLBeacon nearest = null;

            foreach (var beacon in e.Beacons.Where(b => b.Rssi != 0))
            {
                Debug.WriteLine("Ranged {0} {1}.{2} - distance {3}",
                                beacon.ProximityUuid.AsString(),
                                beacon.Major,
                                beacon.Minor,
                                beacon.Rssi);

                if (nearest == null || nearest.Rssi < beacon.Rssi)
                {
                    nearest = beacon;
                }
            }

            if (nearest == null)
            {
                NearestBeacon.Text = "No beacons found";
            }
            else
            {
                NearestBeacon.Text = $"Nearest Beacon is {nearest.Major}.{nearest.Minor}";
            }
        }
        private Beacon FromCLBeacon(CLBeacon device)
        {
            Beacon beacon = new Beacon();

            beacon.Minor = device.Minor.Int16Value;
            beacon.Major = device.Major.Int16Value;
            DistanceType d = DistanceType.UNKNOWN;

            switch (device.Proximity)
            {
            case CLProximity.Immediate:
                d = DistanceType.INMEDIATE;
                break;

            case CLProximity.Near:
                d = DistanceType.NEAR;
                break;

            case CLProximity.Far:
                d = DistanceType.FAR;
                break;

            case CLProximity.Unknown:

                break;
            }

            beacon.Distance = d;

            return(beacon);
        }
        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);
        }
Exemple #4
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();
        }
        void SetProximity(CLBeacon source, BeaconItem dest)
        {
            Proximity p = Proximity.Unknown;

            switch (source.Proximity)
            {
            case CLProximity.Immediate:
                p = Proximity.Immediate;
                break;

            case CLProximity.Near:
                p = Proximity.Near;
                break;

            case CLProximity.Far:
                p = Proximity.Far;
                break;
            }

            if (p > dest.Proximity || p < dest.Proximity)
            {
                dest.ProximityChangeTimestamp = DateTime.Now;
            }

            dest.Proximity = p;
        }
Exemple #6
0
        void SetProximity(CLBeacon source, BeaconItem dest)
        {
            CLProximity p = CLProximity.Unknown;

            switch (source.Proximity)
            {
            case CLProximity.Immediate:
                p = CLProximity.Immediate;
                var notification = new UILocalNotification
                {
                    FireDate    = NSDate.FromTimeIntervalSinceNow(1),
                    AlertAction = "Device Proximity Alert",
                    AlertBody   = "We are close to required bluetooth device!",
                    SoundName   = UILocalNotification.DefaultSoundName
                };
                //notify main app about beacon proximity
                UIApplication.SharedApplication.ScheduleLocalNotification(notification);
                break;

            case CLProximity.Near:
                p = CLProximity.Near;
                break;

            case CLProximity.Far:
                p = CLProximity.Far;
                break;
            }


            dest.Proximity = p;
        }
Exemple #7
0
 public override void DidRangeBeacons(CLLocationManager manager, CLBeacon[] beacons, CLBeaconRegion region)
 {
     //base.DidRangeBeacons(manager, beacons, region);
     Console.WriteLine("Ranging Beacons");
     if (beacons.Length > 0)
     {
         CLBeacon selectedBeacon = (CLBeacon)beacons.GetValue(0);
         Console.WriteLine(selectedBeacon.ProximityUuid.ToString() + "|" + selectedBeacon.Proximity.ToString());
     }
 }
		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 ();
		}
Exemple #9
0
    void DidRangeBeacons(object sender, CLLocationManager.DidRangeBeaconsEventArgs e)
    {
        if (e.beacons.Length == 0)
        {
            return;
        }

        CLBeacon beacon = e.beacons[0] as CLBeacon;

        Log("distance: " + beacon.proximity);
    }
Exemple #10
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);
        }
Exemple #11
0
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            int    i          = indexPath.Section;
            string identifier = inProgress && i == 0 ? "ProgressCell" : "BeaconCell";

            UITableViewCell cell = tableView.DequeueReusableCell(identifier);

            if (cell == null)
            {
                // Show the indicator that denotes calibration is in progress.
                if (identifier == "ProgressCell")
                {
                    cell = new UITableViewCell(UITableViewCellStyle.Default, identifier)
                    {
                        SelectionStyle = UITableViewCellSelectionStyle.None
                    };

                    progressBar.Center = new PointF(cell.Center.X, 17.0f);
                    cell.ContentView.AddSubview(progressBar);

                    UILabel label = new UILabel(new RectangleF(0.0f, 0.0f, 300.0f, 15.0f))
                    {
                        AutoresizingMask = UIViewAutoresizing.FlexibleMargins,
                        BackgroundColor  = UIColor.Clear,
                        Center           = new PointF(cell.Center.X, 30.0f),
                        Font             = UIFont.SystemFontOfSize(11.0f),
                        Text             = "Wave device side-to-side 1m away from beacon",
                        TextAlignment    = UITextAlignment.Center,
                        TextColor        = UIColor.DarkGray
                    };
                    cell.ContentView.AddSubview(label);
                }
                else
                {
                    cell = new UITableViewCell(UITableViewCellStyle.Subtitle, identifier);
                }
            }

            if (identifier == "ProgressCell")
            {
                return(cell);
            }

            CLBeacon beacon = beacons [GetNonEmptySection(indexPath.Section)] [indexPath.Row];

            cell.TextLabel.Text       = beacon.ProximityUuid.AsString();
            cell.TextLabel.Font       = UIFont.SystemFontOfSize(20.0f);
            cell.DetailTextLabel.Text = String.Format("Major: {0}  Minor: {1}  Acc: {2:0.00}m",
                                                      beacon.Major, beacon.Minor, beacon.Accuracy);

            return(cell);
        }
Exemple #12
0
        private void SendBeaconChangeProximity(CLBeacon beacon)
        {
            System.Diagnostics.Debug.WriteLine("SendBeaconChangeProximity");

            if (beacon.Proximity == CLProximity.Unknown)
            {
                System.Diagnostics.Debug.WriteLine(CLProximity.Unknown);
                return;
            }

            // TODO ビーコン追加
            string uuid  = beacon.ProximityUuid.AsString();
            var    major = (ushort)beacon.Major;
            var    minor = (ushort)beacon.Minor;

            System.Diagnostics.Debug.WriteLine(beacon.ToString());
        }
Exemple #13
0
        private void SendBeaconChangeProximity(CLBeacon beacon)
        {
            Mvx.Resolve <IMvxTrace>().Trace(MvxTraceLevel.Diagnostic, "Beacon", string.Format("Founded Beacon {1}:{2}:{3} - {4} - {0}", beacon.Proximity, beacon.ProximityUuid.AsString(), beacon.Major, beacon.Minor, beacon.Rssi));

            if (beacon.Proximity == CLProximity.Unknown)
            {
                Mvx.Resolve <IMvxTrace>().Trace(MvxTraceLevel.Diagnostic, "Beacon", "Location Unknown" + beacon.Description);
                return;
            }

            string uuid  = beacon.ProximityUuid.AsString();
            var    major = (ushort)beacon.Major;
            var    minor = (ushort)beacon.Minor;

            Mvx.Resolve <IMvxMessenger>().Publish <BeaconFoundMessage> (
                new BeaconFoundMessage(this, uuid, major, minor)
                );
        }
Exemple #14
0
        public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
        {
            UITableViewCell cell = tableView.DequeueReusableCell("Cell");

            if (cell == null)
            {
                cell = new UITableViewCell(UITableViewCellStyle.Subtitle, "Cell");
                cell.SelectionStyle = UITableViewCellSelectionStyle.None;
            }

            // Display the UUID, major, minor and accuracy for each beacon.
            CLBeacon beacon = beacons [GetNonEmptySection(indexPath.Section)] [indexPath.Row];

            cell.TextLabel.Text       = beacon.ProximityUuid.AsString();
            cell.DetailTextLabel.Text = String.Format("Major: {0}  Minor: {1}  Acc: {2:0.00}m",
                                                      beacon.Major, beacon.Minor, beacon.Accuracy);
            return(cell);
        }
        private void LocationManager_DidRangeBeacons(object sender, CLRegionBeaconsRangedEventArgs e)
        {
            CLBeacon nearestBeacon = null;

            if (e.Beacons.Any(m => m.Rssi < 0))  //ignore any 0 values and find the nearest beacon.
            {
                foreach (CLBeacon beacon in e.Beacons)
                {
                    Debug.WriteLine("Found beacon {0} {1}.{2} - rssi {3}", beacon.ProximityUuid.AsString(), beacon.Major, beacon.Minor, beacon.Rssi);
                    //var nearestBeacon = e.Beacons.OrderBy(x => x.Rssi).FirstOrDefault();

                    if (nearestBeacon == null)
                    {
                        nearestBeacon = beacon;
                    }
                    else if (beacon.Rssi > nearestBeacon.Rssi)
                    {
                        nearestBeacon = beacon;
                    }
                    this.NearestLockUuid = Guid.Parse(nearestBeacon.ProximityUuid.AsString());
                    Debug.WriteLine("Nearest beacon is {0}", this.NearestLockUuid);

                    //now that we have the nearest beacon, check if rssi is > -50 (or config value) and then send unlock request
                    if (nearestBeacon.Rssi > -60)
                    {
                        //stop ranging -? nned to have the CLregion
                        //_locationManager.RangedRegions.Where(x => x.re)
                        StopAllRanging();

                        //send unlock requests
                        Debug.WriteLine("Sending Unlock request");
                        SendUnlockRequest();
                        Debug.WriteLine("Unlock request sent");


                        Thread.Sleep(15000);
                        //start ranging
                        StartAllRanging();
                    }
                }
            }
        }
        public override void DidRangeBeacons(CLLocationManager manager, CLBeacon[] beacons, CLBeaconRegion region)
        {
            //I use this to watch how many ranges I get on region enter/exit when app is in
            //background mode
//			i += 1;
//			Console.WriteLine ("ranging " + i);

            if (beacons.Length > 0)
            {
                CLBeacon selectedBeacon = (CLBeacon)beacons.GetValue(0);

                //If the beacon is near or immediate show content.
                //This should be enhanced to handle only setting and showing once vs over and over again
                //Might also implement different content for each proximty type
                if (selectedBeacon.Proximity == CLProximity.Near)
                {
                    SetContent(_beaconManager.GetBeaconContent(selectedBeacon, region));
                }
            }
        }
Exemple #17
0
        void LocationManagerDidRangeBeacons(object sender, CLRegionBeaconsRangedEventArgs e)
        {
            CLBeacon nearest = null;

            _sharedBeacons = new List <SharedBeacon>();

            foreach (var beacon in e.Beacons.Where(b => b.Rssi != 0))
            {
                var rssi_to_string = beacon.Rssi.ToString();
                var rssi_to_int    = int.Parse(rssi_to_string, NumberStyles.AllowLeadingSign);
                Debug.WriteLine(rssi_to_int);

                var distance = getdistance(rssi_to_int, -69);


                Debug.WriteLine("Ranged {0} {1}.{2} - distance {3}",
                                beacon.ProximityUuid.AsString(),
                                beacon.Major,
                                beacon.Rssi,
                                distance);
                _sharedBeacons.Add(new SharedBeacon("Conatct_tracing", "66:4E:32:66:3C:61", beacon.ProximityUuid.AsString(), beacon.Major.ToString(), beacon.Minor.ToString(), distance, rssi_to_int));

                if (nearest == null || nearest.Rssi < beacon.Rssi)
                {
                    nearest = beacon;
                }
            }

            Task.Run(() =>
            {
                // I send beacons to XF project
                if (_sharedBeacons.Count > 0)
                {
                    Debug.WriteLine("I SEND TO XF " + _sharedBeacons.Count + " BEACONS");
                    Xamarin.Forms.MessagingCenter.Send <App, List <SharedBeacon> >((App)Xamarin.Forms.Application.Current, "BeaconsReceived", _sharedBeacons);
                }
            });
        }
Exemple #18
0
        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);
        }
Exemple #19
0
 public ProximityDemoViewController(CLBeacon beacon)
 {
     this.beacon = beacon;
 }
 public static int OrderByProximity(CLBeacon obj)
 {
     return obj.Proximity == CLProximity.Unknown ? 4 : (int)obj.Proximity;
 }
        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");
        }
Exemple #22
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 });
		}
Exemple #23
0
		void SetProximity (CLBeacon source, BeaconItem dest)
		{

			Proximity p = Proximity.Unknown;

			switch (source.Proximity) {
			case CLProximity.Immediate:
				p = Proximity.Immediate;
				break;
			case CLProximity.Near:
				p = Proximity.Near;
				break;
			case CLProximity.Far:
				p = Proximity.Far;
				break;
			}

			if (p > dest.Proximity || p < dest.Proximity) {
				dest.ProximityChangeTimestamp = DateTime.Now;
			} 

			dest.Proximity = p;
		}
 public DistanceDemoViewController(CLBeacon beacon)
 {
     this.beacon = beacon;
 }
        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);
            }
        }
Exemple #26
0
 public Beacon(CLBeacon beacon)
 {
     this.beacon = beacon;
     this.Uuid   = this.beacon.ProximityUuid.AsString();
 }
 private string GetGuid(CLBeacon beacon)
 {
     var notGuid = beacon.ProximityUuid.ToString();
     return notGuid.Substring(notGuid.IndexOf("> ") + 2);
 }
Exemple #28
0
 public DistanceDemoViewController(CLBeacon beacon)
 {
     this.beacon = beacon;
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.NavigationController.NavigationBar.Translucent = true;
            //Estilos para la barra de navegacion
            this.NavigationController.NavigationBar.TintColor = UIColor.Gray;
            //this.NavigationController.NavigationBar.BarTintColor =  UIColor.Blue;
            this.NavigationController.NavigationBar.Translucent = true;
            //Fin estilos barra navegacion

            GetData();
            DataSource data = new DataSource(jsonObj, this);

            tvDatos.Source = data;
            tvDatos.ReloadData();
            tvDatos.ReloadInputViews();

            //Nuevos beacons

            var settings = UIUserNotificationSettings.GetSettingsForTypes(
                UIUserNotificationType.Alert
                | UIUserNotificationType.Badge
                | UIUserNotificationType.Sound,
                new NSSet());

            UIApplication.SharedApplication.RegisterUserNotificationSettings(settings);

            locationMgr = new CLLocationManager();

            if (locationMgr.RespondsToSelector(new Selector("requestWhenInUseAuthorization")))
            {
                locationMgr.RequestAlwaysAuthorization();
            }

            //primer beacon
            var shopUUID     = new NSUuid(uuid);
            var beaconRegion = new CLBeaconRegion(shopUUID, firstShopId);

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

            locationMgr.StartMonitoring(beaconRegion);
            locationMgr.StartRangingBeacons(beaconRegion);

            //segundo beacon
            var shop2UUID     = new NSUuid(uuid2);
            var beaconRegion2 = new CLBeaconRegion(shop2UUID, secondShopId);

            beaconRegion2.NotifyEntryStateOnDisplay = true;
            beaconRegion2.NotifyOnEntry             = true;
            beaconRegion2.NotifyOnExit = true;

            locationMgr.StartMonitoring(beaconRegion2);
            locationMgr.StartRangingBeacons(beaconRegion2);



            locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => {
                Console.WriteLine("RegionEntered");

                switch (e.Region.Identifier)
                {
                case "shop2":
                    UILocalNotification notification = new UILocalNotification()
                    {
                        AlertBody = "Existe una promoción A!!!"
                    };
                    UIApplication.SharedApplication.PresentLocationNotificationNow(notification);
                    break;

                case "shop1":
                    UILocalNotification notification2 = new UILocalNotification()
                    {
                        AlertBody = "Existe una promoción B!!!"
                    };
                    UIApplication.SharedApplication.PresentLocationNotificationNow(notification2);
                    break;
                }

                /*
                 * if (e.Region.Identifier == secondShopId) {
                 *      UILocalNotification notification = new UILocalNotification () { AlertBody = "Existe una promoción A!!!" };
                 *      UIApplication.SharedApplication.PresentLocationNotificationNow (notification);
                 * }
                 * if (e.Region.Identifier == firstShopId) {
                 *      UILocalNotification notification = new UILocalNotification () { AlertBody = "Existe una promoción B!!!" };
                 *      UIApplication.SharedApplication.PresentLocationNotificationNow (notification);
                 * }
                 */
            };

            locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => {
                System.Diagnostics.Debug.WriteLine("Entramos");
                if (e.Beacons.Length > 0)
                {
                    if (e.Region.Identifier == firstShopId)
                    {
                        CLBeacon beacon = e.Beacons [0];
                        switch (beacon.Proximity)
                        {
                        case CLProximity.Immediate:
                            Console.WriteLine("Beacon 1");
                            var CategoryVC = new iBeaconVC();
                            this.NavigationController.PresentViewController(CategoryVC, true, null);
                            break;
                        }
                    }
                    if (e.Region.Identifier == secondShopId)
                    {
                        CLBeacon beacon = e.Beacons [0];
                        switch (beacon.Proximity)
                        {
                        case CLProximity.Immediate:
                            Console.WriteLine("Beacon 2");
                            var Category2VC = new Catego2ViewController();
                            this.NavigationController.PresentViewController(Category2VC, true, null);
                            break;
                        }
                    }
                }
            };



            //locationMgr.StartMonitoring (beaconRegion2);
            //locationMgr.StartRangingBeacons (beaconRegion2);


            //this.NavigationController.PushViewController(CategoryVC, true);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

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

            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);

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

                locationMgr.StartMonitoring(beaconRegion);
                locationMgr.StartRangingBeacons(beaconRegion);
            }
        }
        private Beacon FromCLBeacon(CLBeacon device)
        {
            Beacon beacon = new Beacon();

            beacon.Minor = device.Minor.Int16Value;
            beacon.Major = device.Major.Int16Value;
            DistanceType d = DistanceType.UNKNOWN;
            switch (device.Proximity) {
            case CLProximity.Immediate:
                d = DistanceType.INMEDIATE;
                break;
            case CLProximity.Near:
                d = DistanceType.NEAR;
                break;
            case CLProximity.Far:
                d = DistanceType.FAR;
                break;
            case CLProximity.Unknown:

                break;
            }

            beacon.Distance = d;

            return beacon;
        }
        private string GetGuid(CLBeacon beacon)
        {
            var notGuid = beacon.ProximityUuid.ToString();

            return(notGuid.Substring(notGuid.IndexOf("> ") + 2));
        }
Exemple #33
0
 public iOSBeacon(CLBeacon clBeacon)
 {
     CLBeacon = clBeacon;
 }
 private void FoundBeacon(CLBeacon beacon)
 {
     HandleFoundBeacon(beacon.ProximityUuid.AsString(), (ushort)beacon.Major, (ushort)beacon.Minor);
 }
 public ProximityDemoViewController(CLBeacon beacon)
 {
     this.beacon = beacon;
 }