private void StartAllRanging() { foreach (Lock item in this.Locks) { CLBeaconRegion region = new CLBeaconRegion(new NSUuid(item.LockUUID.ToString()), item.LockName); _locationManager.StartRangingBeacons(region); } }
void LocationManagerAuthorizationChanged(object sender, CLAuthorizationChangedEventArgs e) { Debug.WriteLine("Authorisation state: {0}", e.Status); if (e.Status == CLAuthorizationStatus.AuthorizedAlways) { _locationManager.StartRangingBeacons(_region); } }
void HandleRegionEntered(object sender, CLRegionEventArgs e) { Console.WriteLine("Region entered: " + e.Region.Identifier); if (e.Region.Identifier.Equals(roximityBeaconId)) { locationManager.StartRangingBeacons(rBeaconRegion); var notification = new UILocalNotification { AlertBody = "Beacons are in range" }; UIApplication.SharedApplication.PresentLocalNotificationNow(notification); } }
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 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 void StartRagingBeacons(UserDataModel userData) { System.Diagnostics.Debug.WriteLine("StartBeacon"); _listOfCLBeaconRegion.Add(_fieldRegion); _locationManager.StartRangingBeacons(_fieldRegion); }
public void StartBeacon() { System.Diagnostics.Debug.WriteLine("StartBeacon"); _locationMgr.RequestAlwaysAuthorization(); _locationMgr.DidRangeBeacons += HandleDidRangeBeacons; _locationMgr.DidDetermineState += HandleDidDetermineState; _locationMgr.PausesLocationUpdatesAutomatically = false; _locationMgr.StartUpdatingLocation(); _locationMgr.RequestAlwaysAuthorization(); _listOfCLBeaconRegion.Add(clBeaconRegion); _locationMgr.StartMonitoring(clBeaconRegion); _locationMgr.StartRangingBeacons(clBeaconRegion); // #if DEBUG // var beacon = _listOfCLBeaconRegion.First(); // string uuid = beacon.ProximityUuid.AsString (); // var major = (ushort)beacon.Major; // var minor = (ushort)beacon.Minor; // // Mvx.Resolve<IMvxMessenger>().Publish<BeaconChangeProximityMessage> ( // new BeaconChangeProximityMessage (this, uuid, major, minor) // ); // #endif }
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); }
void StartRangingAllRegions() { foreach (CLBeaconRegion region in rangedRegions) { locationManager.StartRangingBeacons(region); } }
public override void DidDetermineState(CLLocationManager manager, CLRegionState state, CLRegion region) { //base.DidDetermineState(manager, state, region); if (state == CLRegionState.Inside) { manager.StartRangingBeacons(region as CLBeaconRegion); } }
public override void ViewWillAppear(bool animated) { base.ViewWillAppear(animated); foreach (CLBeaconRegion region in rangedRegions) { locationManager.StartRangingBeacons(region); } }
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"); }
/// <summary> /// Handles Ranging on/off /// </summary> /// <param name="shouldRange">If set to <c>true</c> should range.</param> void RangeBeacons() { if (!(UIApplication.SharedApplication.ApplicationState == UIApplicationState.Background)) { imgAdd.Image = UIImage.FromBundle(Globals.DefaultImage); lblAddtext.Text = Globals.DefaultText; } _locationManager.StartRangingBeacons(_beaconRegion); _locationManager.RequestState(_beaconRegion); }
public void AddEvent(Guid uuid, ushort major, ushort minor, short thresholdRssi, int intervalMilliSec, Action func) { //TODO: 非同期メソッドや引数ありのメソッドもセットできるようにしたい iBeaconEventHolder eventHolder = new iBeaconEventHolder(uuid, major, minor); if (!_beaconEventHolderDict.ContainsKey(eventHolder.BeaconIdentifyStr)) { _beaconEventHolderDict.Add(eventHolder.BeaconIdentifyStr, eventHolder); } _beaconEventHolderDict[eventHolder.BeaconIdentifyStr].AddEvent(thresholdRssi, intervalMilliSec, func); if (IsScanning) { var nsUuid = new NSUuid(uuid.ToString()); var beaconRegion = new CLBeaconRegion(nsUuid, major, minor, eventHolder.BeaconIdentifyStr); _locationManager.StartRangingBeacons(beaconRegion); } }
public void listen() { var gimbalUUID = new NSUuid(uuid_gimbal); beaconRegion = new CLBeaconRegion(gimbalUUID, gimbalId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; locationManager = new CLLocationManager(); locationManager.RequestAlwaysAuthorization(); locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e?.Region.Identifier == gimbalId) { FoundGimbal("There's a gimbal nearby!"); } }; locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e?.Beacons.Length > 0) { var beacon = e.Beacons.FirstOrDefault(); switch (beacon.Proximity) { case CLProximity.Immediate: OnUpdateDisplay(new GimbalEventArgs("You found the gimbal!", Color.Green)); break; case CLProximity.Near: OnUpdateDisplay(new GimbalEventArgs("You're near the gimbal!", Color.Yellow)); break; case CLProximity.Far: OnUpdateDisplay(new GimbalEventArgs("You're far from the gimbal!", Color.Red)); break; case CLProximity.Unknown: OnUpdateDisplay(new GimbalEventArgs("Got no idea where the gimbal is!", Color.Gray)); break; } previousProximity = beacon.Proximity; } }; locationManager.StartMonitoring(beaconRegion); locationManager.StartRangingBeacons(beaconRegion); }
public BeaconMonitor() { locationManager = new CLLocationManager(); var beaconRegion = new CLBeaconRegion(new NSUuid(PollViewModel.LOOKUP_UUID), "My Beacon") { NotifyEntryStateOnDisplay = true, NotifyOnEntry = true }; locationManager.RegionEntered += (s, e) => { if (e.Region.Identifier == "My Beacon") { Console.WriteLine("Found My Beacon"); locationManager.StartRangingBeacons(beaconRegion); locationManager.DidRangeBeacons += (lm, e2) => { if (e2.Beacons.Length > 0) { foreach (var b in e2.Beacons) { if (b.Proximity != CLProximity.Unknown) { Console.WriteLine("UUID: {0} | Major: {1} | Minor: {2} | Accuracy: {3} | Proximity: {4} | RSSI: {5}", b.ProximityUuid, b.Major, b.Minor, b.Accuracy, b.Proximity, b.Rssi); var exists = false; foreach (var beacon in Beacons) { if (beacon.Minor.Equals(b.Minor.ToString())) { beacon.CurrentDistance = Math.Round(b.Accuracy, 2); SetProximity(b, beacon); exists = true; } } if (!exists) { var newBeacon = new BeaconItem { Minor = b.Minor.ToString(), Name = "", CurrentDistance = Math.Round(b.Accuracy, 2) }; SetProximity(b, newBeacon); Beacons.Add(newBeacon); } } } } }; } }; locationManager.StartMonitoring(beaconRegion); }
public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. LocationManager.DidRangeBeacons += LocationManager_DidRangeBeacons; BeaconRegion = new CLBeaconRegion(AppDelegate.RegionUuid, "RangingBeacon"); LocationManager.StartRangingBeacons(BeaconRegion); }
public override void ViewDidLoad () { base.ViewDidLoad (); Near = UIImage.FromBundle ("Images/square_near"); Far = UIImage.FromBundle ("Images/square_far"); Immediate = UIImage.FromBundle ("Images/square_immediate"); Unknown = UIImage.FromBundle ("Images/square_unknown"); beaconUUID = new NSUuid (uuid); beaconRegion = new CLBeaconRegion (beaconUUID, beaconMajor, beaconId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; locationmanager = new CLLocationManager (); locationmanager.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == beaconId) { var notification = new UILocalNotification () { AlertBody = "The Xamarin beacon is close by!" }; UIApplication.SharedApplication.CancelAllLocalNotifications(); UIApplication.SharedApplication.PresentLocationNotificationNow (notification); } }; locationmanager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e.Beacons.Length > 0) { CLBeacon beacon = e.Beacons [0]; //this.Title = beacon.Proximity.ToString() + " " +beacon.Major + "." + beacon.Minor; } dataSource.Beacons = e.Beacons; TableView.ReloadData(); }; locationmanager.StartMonitoring (beaconRegion); locationmanager.StartRangingBeacons (beaconRegion); TableView.Source = dataSource = new DataSource (this); }
void StartBeaconMonitoring() { var isAvailable = CLLocationManager.IsMonitoringAvailable(typeof(CLRegion)); if (CLLocationManager.IsRangingAvailable && isAvailable) { locationMgr.StartRangingBeacons(beaconRegion); locationMgr.StartMonitoring(beaconRegion); } Console.WriteLine("CLLocationManager.IsRangingAvailable && CLLocationManager.IsMonitoringAvailable(typeof(CLRegion)"); Console.WriteLine(CLLocationManager.IsRangingAvailable.ToString() + " & " + CLLocationManager.IsMonitoringAvailable(typeof(CLRegion))); }
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); }
// When Beacon enter the region created in StartMonitoring() public override void RegionEntered(CLLocationManager manager, CLRegion region) { base.RegionEntered(manager, region); if (region is CLBeaconRegion) { // Start ranging only if the feature is available and isRangingActive is set to true if (CLLocationManager.IsRangingAvailable && isRangingActive) { manager.StartRangingBeacons((CLBeaconRegion)region); } } }
/// <summary> /// Starts the monitoring region. /// </summary> /// <param name="UUID">UUI.</param> public void StartMonitoringRegion(string UUID) { rangingBeacons.Clear(); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) { #if DEBUG SystemLogger.Log(SystemLogger.Module.PLATFORM, "Using new iOS 8 Location Services Authorization"); #endif locationManager.RequestWhenInUseAuthorization(); //only requests for authorization in app running (foreground) } /*if (adapter != null) { * if (adapter.IsScanning) { * this.StopMonitoringBeacons (); * } * Guid region = new Guid (UUID); * adapter.StartScanningForDevices (region); * SystemLogger.Log("adapter.StartScanningForDevices(" + UUID +")"); * }*/ Unknowns = new List <CLBeacon> (); Immediates = new List <CLBeacon> (); Nears = new List <CLBeacon> (); Fars = new List <CLBeacon> (); beaconsLocation = new List <CLBeacon> [4] { Unknowns, Immediates, Nears, Fars }; NSUuid uuid; if (UUID != null && UUID.Any()) { uuid = new NSUuid(UUID); SystemLogger.Log(SystemLogger.Module.PLATFORM, "uuid: " + UUID); regionLocation = new CLBeaconRegion(uuid, uuid.AsString()); locationManager.StartRangingBeacons(regionLocation); } timeStop = new Timer(); timeStop.Interval = 5000; timeStop.Start(); timeStop.Elapsed += (x, y) => { SystemLogger.Log(SystemLogger.Module.PLATFORM, "STOPPED!"); if (timeStop != null) { timeStop.Stop(); } this.StopMonitoringBeacons(); }; //timeStop.Elapsed += this.StopMonitoringBeacons (); //NSTimer.CreateScheduledTimer(new TimeSpan(5000), new Action }
public void StartMonitoring(string uuid, string id) { var beaconUUID = new NSUuid(uuid); beaconRegion = new CLBeaconRegion(beaconUUID, id); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; locationManager.RequestAlwaysAuthorization(); locationManager.DistanceFilter = 0.5; locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => { //This can be used for firing events when personnel come into hospitals. }; locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e?.Beacons.Length > 0) { var beacon = e.Beacons.FirstOrDefault(); int?roomBeacon; switch (beacon.Proximity) { case CLProximity.Far: case CLProximity.Unknown: roomBeacon = null; break; default: roomBeacon = beacon.Minor.Int32Value; break; } if (roomBeacon != previousBeacon) { OnDidRangeBeacons(new BeaconRangedEventArgs(roomBeacon)); } previousBeacon = roomBeacon; } }; locationManager.StartMonitoring(beaconRegion); locationManager.StartRangingBeacons(beaconRegion); }
private void StartRanging() { StopRanging(); if (viewModel == null || viewModel.Prize == null) { return; } if (secretRegion == null) { secretRegion = new CLBeaconRegion(new NSUuid(viewModel.UUID), 9999, BeaconId); } manager.StartRangingBeacons(secretRegion); }
public void StartScan(List <Guid> BeaconsUUID) { // 把要監聽的Beacon uuid轉換成系統API需要的物件 beaconsRegion = new List <CLBeaconRegion>(); var UUIDObjects = BeaconsUUID.Select(c => new NSUuid(c.ToString())); beaconsRegion.AddRange( UUIDObjects.Select(c => new CLBeaconRegion(c, c.AsString()))); // 開始監聽beacon廣播 foreach (CLBeaconRegion beaconRegion in beaconsRegion) { locationManager.StartRangingBeacons(beaconRegion); } }
public BeaconLocatorIPhone(List <string> phoneNumbers) { Initialize(); _phoneNumerList = phoneNumbers; foreach (var phoneNumber in phoneNumbers) { var beaconInfo = GetBeaconInfo(phoneNumber); beaconInfo.BeaconRegion.NotifyEntryStateOnDisplay = true; beaconInfo.BeaconRegion.NotifyOnEntry = true; beaconInfo.BeaconRegion.NotifyOnExit = true; _locationMgr.StartMonitoring(beaconInfo.BeaconRegion); _locationMgr.StartRangingBeacons(beaconInfo.BeaconRegion); _beaconInfoList.Add(beaconInfo); } }
public override void ViewDidLoad() { base.ViewDidLoad(); var beaconRegion = new CLBeaconRegion(UUID, major, regionIdentifier); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; locationMgr = new CLLocationManager(); locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == regionIdentifier) { UILocalNotification notification = new UILocalNotification() { AlertBody = "Beacon Located" }; UIApplication.SharedApplication.PresentLocationNotificationNow(notification); titleLabel.Text = "Found Beacon!"; } }; locationMgr.RegionLeft += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == regionIdentifier) { titleLabel.Text = "Lost Beacon :("; } }; locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e.Beacons.Length > 0) { var beacon = e.Beacons[0]; subTitleLabel.Text = e.Beacons[0].Proximity.ToString(); detailsLabel.Text = "Strength: " + beacon.Rssi + " Distance: " + beacon.Accuracy.ToString(); } }; locationMgr.StartMonitoring(beaconRegion); locationMgr.StartRangingBeacons(beaconRegion); }
public override void ViewDidLoad() { base.ViewDidLoad(); locationmanager = new CLLocationManager(); locationmanager.RequestWhenInUseAuthorization(); beaconUUID = new NSUuid(uuid); beaconRegion = new CLBeaconRegion(beaconUUID, beaconMajor, beaconMinor, beaconId); locationmanager.DidRangeBeacons += (sender, e) => { if (e.Beacons.Length == 0) { return; } var beacon = e.Beacons[0]; switch (beacon.Proximity) { case CLProximity.Far: View.BackgroundColor = UIColor.Blue; break; case CLProximity.Near: View.BackgroundColor = UIColor.Yellow; break; case CLProximity.Immediate: View.BackgroundColor = UIColor.Green; break; case CLProximity.Unknown: return; } LabelBeacon.Text = beacon.Accuracy.ToString(); }; locationmanager.StartRangingBeacons(beaconRegion); // Perform any additional setup after loading the view, typically from a nib. }
public override void ViewDidLoad() { base.ViewDidLoad(); _locationManager.RequestWhenInUseAuthorization(); _locationManager.DidRangeBeacons += (sender, e) => { if (!e.Beacons.Any()) { return; } var beacon = e.Beacons.First(); InvokeOnMainThread(() => { switch (beacon.Proximity) { case CLProximity.Far: View.BackgroundColor = UIColor.Blue; break; case CLProximity.Near: View.BackgroundColor = UIColor.Yellow; break; case CLProximity.Immediate: View.BackgroundColor = UIColor.Green; break; case CLProximity.Unknown: View.BackgroundColor = UIColor.Red; break; } Status.Text = beacon.Accuracy.ToString(); }); }; _locationManager.StartRangingBeacons(_beaconRegion); }
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(); this.textView = new UITextView(this.View.Bounds); this.locationManager = new CLLocationManager(); var uuid = new NSUuid("B9407F30-F5F8-466E-AFF9-25556B57FE6D"); var region = new CLBeaconRegion(uuid, "myIBeacon"); region.NotifyEntryStateOnDisplay = true; region.NotifyOnEntry = true; region.NotifyOnExit = true; // Request authorization to use location services when app is open. locationManager.RequestWhenInUseAuthorization(); locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => { // Do something when user's device enters range of the beacon. // (i.e, show a notification, send data to //a server, etc.) this.textView.Text += String.Format("[{0:T}] Beacon Region Entered\n", DateTime.Now); }; locationManager.RegionLeft += (object sender, CLRegionEventArgs e) => { // Do something when user's device exits range of the beacon. // (i.e, show a notification, send data to //a server, etc.) this.textView.Text += String.Format("[{0:T}] Beacon Region Left\n", DateTime.Now); }; locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { foreach (var b in e.Beacons) { this.textView.Text += String.Format("[{0:T}] Beacon Ranged: Major = {1}, Minor = {2}\n", DateTime.Now, b.Major, b.Minor); } }; locationManager.StartMonitoring(region); locationManager.StartRangingBeacons(region); }
public void Start(List <BeaconModel> beacons) { _locationMgr.RequestAlwaysAuthorization(); _locationMgr.DidRangeBeacons += HandleDidRangeBeacons; _locationMgr.DidDetermineState += HandleDidDetermineState; _locationMgr.PausesLocationUpdatesAutomatically = false; _locationMgr.StartUpdatingLocation(); _locationMgr.RequestAlwaysAuthorization(); //Начинаем мониторинг foreach (var ibeacon in beacons) { var clBeaconRegion = new CLBeaconRegion(new NSUuid(ibeacon.UUID), ibeacon.Major, ibeacon.Minor, ibeacon.ID.ToString()); clBeaconRegion.NotifyEntryStateOnDisplay = true; clBeaconRegion.NotifyOnEntry = true; clBeaconRegion.NotifyOnExit = true; _listOfCLBeaconRegion.Add(clBeaconRegion); _locationMgr.StartMonitoring(clBeaconRegion); _locationMgr.StartRangingBeacons(clBeaconRegion); Mvx.Resolve <IMvxTrace>().Trace(MvxTraceLevel.Diagnostic, "Beacon", "Start debug " + ibeacon.ID); } // #if DEBUG // var beacon = _listOfCLBeaconRegion.First(); // string uuid = beacon.ProximityUuid.AsString (); // var major = (ushort)beacon.Major; // var minor = (ushort)beacon.Minor; // // Mvx.Resolve<IMvxMessenger>().Publish<BeaconChangeProximityMessage> ( // new BeaconChangeProximityMessage (this, uuid, major, minor) // ); // #endif }
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); }
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(); locationmanager = new CLLocationManager(); if (UIDevice.CurrentDevice.CheckSystemVersion(8, 0)) locationmanager.RequestAlwaysAuthorization(); beaconUUID = new NSUuid(uuid); beaconRegion = new CLBeaconRegion(beaconUUID, beaconMajor, beaconMinor, beaconId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; locationmanager.RegionEntered += (sender, e) => { var notification = new UILocalNotification() { AlertBody = "The Xamarin beacon is close by!" }; UIApplication.SharedApplication.CancelAllLocalNotifications(); UIApplication.SharedApplication.PresentLocalNotificationNow(notification); }; //create beacon region beaconUUID = new NSUuid(uuid); beaconRegion = new CLBeaconRegion(beaconUUID, beaconMajor, beaconMinor, beaconId); locationmanager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e.Beacons == null || e.Beacons.Length == 0) return; LabelBeacon.Text = "We found: " + e.Beacons.Length + " beacons"; var beacon = e.Beacons[0]; switch (beacon.Proximity) { case CLProximity.Far: View.BackgroundColor = UIColor.Blue; break; case CLProximity.Near: View.BackgroundColor = UIColor.Yellow; break; case CLProximity.Immediate: View.BackgroundColor = UIColor.Green; break; } LabelDistance.Text = "We are: " + beacon.Accuracy.ToString("##.000"); if (beacon.Accuracy <= .1 && beacon.Proximity == CLProximity.Immediate) { locationmanager.StopRangingBeacons(beaconRegion); var vc = UIStoryboard.FromName("MainStoryboard", null).InstantiateViewController("FoundViewController"); NavigationController.PushViewController(vc, true); } }; 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 bool startLookingForBeacons() { BeaconList.init (); Console.WriteLine ("create called"); var beaconUUID = new NSUuid (uuid); var beaconRegion = new CLBeaconRegion (beaconUUID, beaconId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; locationManager = new CLLocationManager (); locationManager.RequestWhenInUseAuthorization (); locationManager.DidStartMonitoringForRegion += (object sender, CLRegionEventArgs e) => { locationManager.RequestState (e.Region); }; locationManager.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == beaconId) { Console.WriteLine ("beacon region entered"); } }; locationManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => { switch (e.State) { case CLRegionState.Inside: Console.WriteLine ("region state inside"); break; case CLRegionState.Outside: Console.WriteLine ("region state outside"); break; case CLRegionState.Unknown: default: Console.WriteLine ("region state unknown"); break; } }; locationManager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e.Beacons.Length > 0) { List<BeaconModel> beacons = new List<BeaconModel> {}; for (int i = 0; i < e.Beacons.Length; i++) { CLBeacon beacon = e.Beacons [i]; string proximity = ""; var major = (int) beacon.Major; var minor = (int) beacon.Minor; var accuracy = beacon.Accuracy; Console.WriteLine(beacon.Major.ToString() + " " + beacon.Minor.ToString() + " " + beacon.Accuracy.ToString() ); switch (beacon.Proximity) { case CLProximity.Immediate: proximity = "Immediate"; break; case CLProximity.Near: proximity = "Near"; break; case CLProximity.Far: proximity = "Far"; break; case CLProximity.Unknown: proximity = "Unknown"; break; } BeaconModel beaconModel = new BeaconModel() { Major = major, Minor = minor, Proximity = proximity, Region = e.Region.ToString(), Accuracy = accuracy }; // EventHandler<BeaconTest.onResultEventArgs> handler = onResultEvent; // if (handler != null) // { // handler(this, new BeaconTest.onResultEventArgs{result = message}); // } beacons.Add(beaconModel); } BeaconList.nearbyBeacons = BeaconList.updateList(beacons, BeaconList.nearbyBeacons, _numberOfFailedIterationsToRemove: 10); BeaconList.lastUpdated = (Int32)(DateTime.UtcNow.Subtract(new DateTime(1970,1,1,0,0,0))).TotalSeconds; BeaconList.beaconsUpdated.Invoke(); } }; locationManager.StartMonitoring (beaconRegion); locationManager.StartRangingBeacons (beaconRegion); return true; }
public override void ViewDidLoad() { base.ViewDidLoad (); var monkeyUUID = new NSUuid (uuid); var beaconRegion = new CLBeaconRegion (monkeyUUID, monkeyId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; if (!UserInterfaceIdiomIsPhone) { //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away var power = new NSNumber (-59); NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData (power); peripheralDelegate = new BTPeripheralDelegate (); peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue); peripheralMgr.StartAdvertising (peripheralData); } else { InitPitchAndVolume (); locationMgr = new CLLocationManager (); locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == monkeyId) { UILocalNotification notification = new UILocalNotification () { AlertBody = "There's a monkey hiding nearby!" }; UIApplication.SharedApplication.PresentLocationNotificationNow (notification); } }; locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e.Beacons.Length > 0) { CLBeacon beacon = e.Beacons [0]; string message = ""; switch (beacon.Proximity) { case CLProximity.Immediate: message = "You found the monkey!"; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Green; break; case CLProximity.Near: message = "You're getting warmer"; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Yellow; break; case CLProximity.Far: message = "You're freezing cold"; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Blue; break; case CLProximity.Unknown: message = "I'm not sure how close you are to the monkey";; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Gray; break; } if(previousProximity != beacon.Proximity){ Speak (message); } previousProximity = beacon.Proximity; } }; locationMgr.StartMonitoring (beaconRegion); locationMgr.StartRangingBeacons (beaconRegion); } }
void HandleTouchDown(object sender, EventArgs e) { if (segBeacon.SelectedSegment == 0) { var power = new NSNumber (-59); NSMutableDictionary peripheralData = bRegion.GetPeripheralData (power); pDelegate = new BTPDelegate (); pManager = new CBPeripheralManager (pDelegate, DispatchQueue.DefaultGlobalQueue); pManager.StartAdvertising (peripheralData); } else { locManager = new CLLocationManager (); locManager.RegionEntered += (object s, CLRegionEventArgs ea) => { if (ea.Region.Identifier == "beacon") { UILocalNotification notification = new UILocalNotification () { AlertBody = "Entering beacon region!" }; UIApplication.SharedApplication.PresentLocationNotificationNow (notification); } }; locManager.DidRangeBeacons += (object s, CLRegionBeaconsRangedEventArgs ea) => { if (ea.Beacons.Length > 0) { CLBeacon beacon = ea.Beacons [0]; switch (beacon.Proximity) { case CLProximity.Immediate: this.View.BackgroundColor = UIColor.Green; break; case CLProximity.Near: this.View.BackgroundColor = UIColor.Yellow; break; case CLProximity.Far: this.View.BackgroundColor = UIColor.Red; break; case CLProximity.Unknown: this.View.BackgroundColor = UIColor.Black; break; } } }; locManager.StartMonitoring (bRegion); locManager.StartRangingBeacons (bRegion); } }