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; }
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"); }
void PlaySound(CLProximity proximity) { string loopFilename = null; int playerIndex = -1, numberOfLoops = -1; float volume = 1f; switch (proximity) { case CLProximity.Far: loopFilename = "Jaws2.mp3"; playerIndex = 0; volume = 5f; break; case CLProximity.Near: loopFilename = "Jaws6-loopable.mp3"; playerIndex = 1; break; case CLProximity.Immediate: loopFilename = "Jaws7.mp3"; numberOfLoops = 0; playerIndex = 2; break; } if (!string.IsNullOrEmpty(loopFilename)) { if (players[playerIndex] == null) { var file = Path.Combine("sounds", loopFilename); var soundUrl = NSUrl.FromFilename(file); players[playerIndex] = AVAudioPlayer.FromUrl(soundUrl); } var player = players [playerIndex]; if (player != null) { player.NumberOfLoops = numberOfLoops; player.Volume = volume; player.PrepareToPlay(); player.Play(); } } for (int i = 0; i < players.Length; i++) { if (i != playerIndex) { if (players[i] != null) { players [i].Stop(); } } } }
public void listen() { var gimbalUUID = new NSUuid(uuid_gimbal); beaconRegion = new CLBeaconRegion(gimbalUUID, gimbalId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; locationManager = new CLLocationManager(); locationManager.RequestAlwaysAuthorization(); locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e?.Region.Identifier == gimbalId) { FoundGimbal("There's a gimbal nearby!"); } }; locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e?.Beacons.Length > 0) { var beacon = e.Beacons.FirstOrDefault(); switch (beacon.Proximity) { case CLProximity.Immediate: OnUpdateDisplay(new GimbalEventArgs("You found the gimbal!", Color.Green)); break; case CLProximity.Near: OnUpdateDisplay(new GimbalEventArgs("You're near the gimbal!", Color.Yellow)); break; case CLProximity.Far: OnUpdateDisplay(new GimbalEventArgs("You're far from the gimbal!", Color.Red)); break; case CLProximity.Unknown: OnUpdateDisplay(new GimbalEventArgs("Got no idea where the gimbal is!", Color.Gray)); break; } previousProximity = beacon.Proximity; } }; locationManager.StartMonitoring(beaconRegion); locationManager.StartRangingBeacons(beaconRegion); }
private string TextForProximity(CLProximity proximity) { switch (proximity) { case CLProximity.Far: return "Far"; case CLProximity.Immediate: return "Immediate"; case CLProximity.Near: return "Near"; default: return "Unknown"; } }
private UIImage ImageForProximity(CLProximity proximity) { switch (proximity) { case CLProximity.Far: return UIImage.FromFile ("far_image"); case CLProximity.Immediate: return UIImage.FromFile ("near_image"); case CLProximity.Near: return UIImage.FromFile ("immediate_image"); default: return UIImage.FromFile ("unknown_image"); } }
public static IBeaconProximity CLProximityToIBeaconProximity(CLProximity prox) { switch (prox) { case CLProximity.Near: return IBeaconProximity.Near; case CLProximity.Far: return IBeaconProximity.Far; case CLProximity.Immediate: return IBeaconProximity.Immediate; case CLProximity.Unknown: return IBeaconProximity.Near; default: return IBeaconProximity.Near; } }
private string TextForProximity(CLProximity proximity) { switch (proximity) { case CLProximity.Far: return("Far"); case CLProximity.Immediate: return("Immediate"); case CLProximity.Near: return("Near"); default: return("Unknown"); } }
private UIImage ImageForProximity(CLProximity proximity) { switch (proximity) { case CLProximity.Far: return(UIImage.FromFile("far_image")); case CLProximity.Immediate: return(UIImage.FromFile("near_image")); case CLProximity.Near: return(UIImage.FromFile("immediate_image")); default: return(UIImage.FromFile("unknown_image")); } }
public static Proximity FromNative(this CLProximity proximity) { switch (proximity) { case CLProximity.Far: return(Proximity.Far); case CLProximity.Immediate: return(Proximity.Immediate); case CLProximity.Near: return(Proximity.Near); default: return(Proximity.Unknown); } }
protected Proximity FromNative(CLProximity proximity) { switch (proximity) { case CLProximity.Far: return(Proximity.Far); case CLProximity.Immediate: return(Proximity.Immediate); case CLProximity.Near: return(Proximity.Near); case CLProximity.Unknown: default: return(Proximity.Unknown); } }
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); } }
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"); }
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); } } }; //} }
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) { int major, minor; foreach (var beacon in e.Beacons) { major = (int)beacon.Major; minor = (int)beacon.Minor; // Console.WriteLine("Found Beacon with Major = {0} Minor = {1}", major, minor); // Lock on to a specific iBeacon since there are many of them in the Darwin lounge if (major == 51093 && minor == 43988) { switch (beacon.Proximity) { case CLProximity.Immediate: message = "Immediate"; break; case CLProximity.Near: message = "Near"; break; case CLProximity.Far: message = "Far"; break; case CLProximity.Unknown: message = "Unknown"; break; } if (previousProximity != beacon.Proximity) { Console.WriteLine(message); } previousProximity = beacon.Proximity; } } } }; locationManager.StartMonitoring(beaconRegion); locationManager.StartRangingBeacons(beaconRegion); }
public override void ViewDidLoad() { base.ViewDidLoad(); 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); } }
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); } }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. var beaconRegion = new CLBeaconRegion(beaconId, beaconRegionName) { NotifyOnEntry = true, NotifyEntryStateOnDisplay = true, 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(peripheralData); peripheralMgr = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue); } else { locationMgr = new CLLocationManager(); locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == beaconRegionName) { UILocalNotification notification = new UILocalNotification() { AlertBody = "Shark Warning! No Swimming!" }; UIApplication.SharedApplication.PresentLocationNotificationNow(notification); } }; locationMgr.RegionLeft += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == beaconRegionName) { UILocalNotification notification = new UILocalNotification() { AlertBody = "Looks like it's safe to swim." }; UIApplication.SharedApplication.PresentLocationNotificationNow(notification); } }; CLProximity previousProximity = CLProximity.Unknown; locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e.Beacons.Length > 0) { var beacon = e.Beacons[0]; if (beacon.Proximity == previousProximity) { return; } PlaySound(beacon.Proximity); beacon. switch (beacon.Proximity) { case CLProximity.Unknown: case CLProximity.Far: this.statusMessage.Text = "Is it true that most people get attacked by sharks in three feet of water about ten feet from the beach?"; this.View.BackgroundColor = UIColor.FromRGB(238, 214, 175); break; case CLProximity.Near: this.statusMessage.Text = "You're gonna need a bigger boat."; this.View.BackgroundColor = UIColor.FromRGB(206, 223, 239); break; case CLProximity.Immediate: this.statusMessage.Text = "It was nice to know ya."; this.View.BackgroundColor = UIColor.FromRGB(138, 7, 7); break; } previousProximity = beacon.Proximity; } }; locationMgr.StartMonitoring(beaconRegion); locationMgr.StartRangingBeacons(beaconRegion); } }
public override void ViewDidLoad() { base.ViewDidLoad(); var beaconUUID = new NSUuid(uuid); var beaconRegion = new CLBeaconRegion(beaconUUID, beaconId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; locationManager = new CLLocationManager(); locationManager.RequestWhenInUseAuthorization(); locationManager.DidStartMonitoringForRegion += (object sender, CLRegionEventArgs e) => { locationManager.RequestState(e.Region); }; locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == beaconId) { Console.WriteLine("beacon region entered"); } }; locationManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => { switch (e.State) { case CLRegionState.Inside: Console.WriteLine("region state inside"); break; case CLRegionState.Outside: Console.WriteLine("region state outside"); break; case CLRegionState.Unknown: default: Console.WriteLine("region state unknown"); break; } }; locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e.Beacons.Length > 0) { CLBeacon beacon = e.Beacons [0]; switch (beacon.Proximity) { case CLProximity.Immediate: message = "Immediate"; break; case CLProximity.Near: message = "Near"; break; case CLProximity.Far: message = "Far"; break; case CLProximity.Unknown: message = "Unknown"; break; } if (previousProximity != beacon.Proximity) { Console.WriteLine(message); } previousProximity = beacon.Proximity; } }; locationManager.StartMonitoring(beaconRegion); locationManager.StartRangingBeacons(beaconRegion); }
public override void ViewDidLoad() { base.ViewDidLoad (); var monkeyUUID = new NSUuid (uuid); var beaconRegion = new CLBeaconRegion (monkeyUUID, monkeyId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; if (!UserInterfaceIdiomIsPhone) { //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away var power = new NSNumber (-59); NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData (power); peripheralDelegate = new BTPeripheralDelegate (); peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue); peripheralMgr.StartAdvertising (peripheralData); } else { InitPitchAndVolume (); locationMgr = new CLLocationManager (); locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == monkeyId) { UILocalNotification notification = new UILocalNotification () { AlertBody = "There's a monkey hiding nearby!" }; UIApplication.SharedApplication.PresentLocationNotificationNow (notification); } }; locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e.Beacons.Length > 0) { CLBeacon beacon = e.Beacons [0]; string message = ""; switch (beacon.Proximity) { case CLProximity.Immediate: message = "You found the monkey!"; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Green; break; case CLProximity.Near: message = "You're getting warmer"; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Yellow; break; case CLProximity.Far: message = "You're freezing cold"; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Blue; break; case CLProximity.Unknown: message = "I'm not sure how close you are to the monkey";; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Gray; break; } if(previousProximity != beacon.Proximity){ Speak (message); } previousProximity = beacon.Proximity; } }; locationMgr.StartMonitoring (beaconRegion); locationMgr.StartRangingBeacons (beaconRegion); } }
public override void ViewDidLoad () { base.ViewDidLoad (); 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); }