当前位置: 首页>>代码示例>>C#>>正文


C# CLLocationManager.StartRangingBeacons方法代码示例

本文整理汇总了C#中CLLocationManager.StartRangingBeacons方法的典型用法代码示例。如果您正苦于以下问题:C# CLLocationManager.StartRangingBeacons方法的具体用法?C# CLLocationManager.StartRangingBeacons怎么用?C# CLLocationManager.StartRangingBeacons使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CLLocationManager的用法示例。


在下文中一共展示了CLLocationManager.StartRangingBeacons方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RangingVC

		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");
		}
开发者ID:IanLeatherbury,项目名称:MonkeyBeacon,代码行数:56,代码来源:RangingViewController.cs

示例2: ViewDidLoad

		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);
		}
开发者ID:IGetIt-Theo,项目名称:iBeaconsEverywhere,代码行数:53,代码来源:MasterViewController.cs

示例3: StartListeningForBeacons

        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 ();
        }
开发者ID:haitrinh,项目名称:gids,代码行数:20,代码来源:BeaconRanger.cs

示例4: ViewDidLoad

        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);
        }
开发者ID:HanhTruong,项目名称:iBeaconsEverywhere,代码行数:65,代码来源:iBeaconsSimple.iOSViewController.cs

示例5: ViewDidLoad

        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);
            }
        }
开发者ID:ironstine,项目名称:FindTheMonkey,代码行数:78,代码来源:FindTheMonkeyViewController.cs

示例6: HandleTouchDown

        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);
            }
        }
开发者ID:jawbrey,项目名称:Code-ios7,代码行数:45,代码来源:BeaconController.cs

示例7: ViewDidLoad

        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);
            }
        }
开发者ID:Jcarter4u,项目名称:FindTheMonkey,代码行数:74,代码来源:FindTheMonkeyViewController.cs

示例8: startLookingForBeacons

        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;
        }
开发者ID:kcrandall,项目名称:BeaconTest,代码行数:93,代码来源:BeaconHandling_iOS.cs

示例9: ViewDidLoad

        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);
        }
开发者ID:IanLeatherbury,项目名称:mini-hacks,代码行数:71,代码来源:iBeaconMiniHackViewController.cs

示例10: ViewDidLoad

        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);
        }
开发者ID:RodH257,项目名称:xamarinIosBeaconSample,代码行数:39,代码来源:iosBeaconSampleViewController.cs


注:本文中的CLLocationManager.StartRangingBeacons方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。