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


C# CLLocationManager.StartMonitoring方法代码示例

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


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

示例1: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();
            locMan = new CLLocationManager();
            locMan.RequestWhenInUseAuthorization();
            locMan.RequestAlwaysAuthorization();
            // Geocode a city to get a CLCircularRegion,
            // and then use our location manager to set up a geofence
            button.TouchUpInside += (o, e) => {

                // clean up monitoring of old region so they don't pile up
                if(region != null)
                {
                    locMan.StopMonitoring(region);
                }

                // Geocode city location to create a CLCircularRegion - what we need for geofencing!
                var taskCoding = geocoder.GeocodeAddressAsync ("Cupertino");
                taskCoding.ContinueWith ((addresses) => {
                    CLPlacemark placemark = addresses.Result [0];
                    region = (CLCircularRegion)placemark.Region;
                    locMan.StartMonitoring(region);

                });
            };

            // This gets called even when the app is in the background - try it!
            locMan.RegionEntered += (sender, e) => {
                Console.WriteLine("You've entered the region");
            };

            locMan.RegionLeft += (sender, e) => {
                Console.WriteLine("You've left the region");
            };
        }
开发者ID:yofanana,项目名称:recipes,代码行数:35,代码来源:GeofencingViewController.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: ViewDidLoad

		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			// Perform any additional setup after loading the view, typically from a nib.

			var LocationManager = new CLLocationManager();
			LocationManager.RequestWhenInUseAuthorization ();
			LocationManager.RequestAlwaysAuthorization ();

			CLCircularRegion region = new CLCircularRegion (new CLLocationCoordinate2D (+46.833120, +15.34901), 1000.0, "FF Gussendorf");

			if (CLLocationManager.LocationServicesEnabled) {

				LocationManager.DidStartMonitoringForRegion += (o, e) => {
					Console.WriteLine ("Now monitoring region {0}", e.Region.ToString ());
				};

				LocationManager.RegionEntered += (o, e) => {
					Console.WriteLine ("Just entered " + e.Region.ToString ());
				};

				LocationManager.RegionLeft += (o, e) => {
					Console.WriteLine ("Just left " + e.Region.ToString ());
				};

				LocationManager.Failed += (o, e) => {
					Console.WriteLine (e.Error);
				};

				LocationManager.UpdatedLocation += (o, e) => {
					Console.WriteLine ("Lat " + e.NewLocation.Coordinate.Latitude + ", Long " + e.NewLocation.Coordinate.Longitude);
				};

				LocationManager.LocationsUpdated += (o, e) => Console.WriteLine ("Location change received");

				LocationManager.StartMonitoring (region);
				LocationManager.StartMonitoringSignificantLocationChanges ();

				//LocationManager.StopMonitoringSignificantLocationChanges ();



			} else {
				Console.WriteLine ("This app requires region monitoring, which is unavailable on this device");
			}
		}
开发者ID:martinlipp,项目名称:GeoFence,代码行数:46,代码来源:ViewController.cs

示例4: 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

示例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 ();

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

              };

              locationmanager.RegionLeft += (sender, e) =>
              {
            var notification = new UILocalNotification () { AlertBody = "The Xamarin beacon is far!" };
            UIApplication.SharedApplication.CancelAllLocalNotifications();
            UIApplication.SharedApplication.PresentLocalNotificationNow (notification);
              };

            //DidRangeBeacons
              locationmanager.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) =>
              {

            if(e.Beacons.Length == 0)
              return;

            var beacon = e.Beacons[0];

            LabelBeacon.Text = "We found: " + e.Beacons.Length + " beacons" +  " " + beacon.Major + " " + beacon.Minor;
            LabelDistance.Text = beacon.Accuracy.ToString("##.000") + " " + beacon.Proximity.ToString();

            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;

              //locationmanager.StopRangingBeacons(beaconRegion);

              //var vc = UIStoryboard.FromName("MainStoryboard", null).InstantiateViewController("FoundViewController");
              //NavigationController.PushViewController(vc, true);
              break;
            case CLProximity.Unknown:
              return;
            }
              };

            //StartRanging
              locationmanager.StartRangingBeacons(beaconRegion);
              locationmanager.StartMonitoring (beaconRegion);
        }
开发者ID:stronachconsult,项目名称:iBeaconsEverywhere,代码行数:66,代码来源:iBeaconsSimple.iOSViewController.cs

示例8: 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

示例9: 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

示例10: ViewDidLoad

        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            CLCircularRegion region = new CLCircularRegion(new CLLocationCoordinate2D(10.009176843388, 76.3615990792536), 20.0, "Jubin's Desk");

            locLabel = (UILabel)this.View.ViewWithTag(2004);
            locLabel1 = (UILabel)this.View.ViewWithTag(2005);
            statusLabel = (UILabel)this.View.ViewWithTag(2006);
            locLabel.Text = "Location...";
            locManager = new CLLocationManager();
            locManager.RequestAlwaysAuthorization ();
            //locManager.RequestWhenInUseAuthorization ();
            locManager.DesiredAccuracy = CLLocation.AccuracyBest;
            //locManager.DistanceFilter = 5.0;
            locManager.UpdatedLocation+=(object sender, CLLocationUpdatedEventArgs e) => {
                locLabel.Text = "Longitude: "+e.NewLocation.Coordinate.Longitude+" Lattitude: "+e.NewLocation.Coordinate.Latitude;
                System.Diagnostics.Debug.WriteLine("Longitude: "+e.NewLocation.Coordinate.Longitude+" Lattitude: "+e.NewLocation.Coordinate.Latitude);
            };
            /* this gets fired and works fine */
            locManager.LocationsUpdated+=(object sender, CLLocationsUpdatedEventArgs e) => {
                foreach (CLLocation aLocation in e.Locations)
                {
                    locLabel1.Text = "Longitude: "+aLocation.Coordinate.Longitude.ToString()+" Lattitude: "+aLocation.Coordinate.Latitude.ToString();
                    if (region.ContainsCoordinate(new CLLocationCoordinate2D(aLocation.Coordinate.Latitude, aLocation.Coordinate.Longitude)))
                    {
                        statusLabel.Text = "Normal location update: cordinates inside the region";
                    }
                    else
                    {
                        statusLabel.Text = "Normal location update: cordinates outside the region";
                    }
                }
            };
            locManager.StartUpdatingLocation();

            if (CLLocationManager.IsMonitoringAvailable (typeof(CLCircularRegion)))
            {
                /* This doesn't get fired */
                locManager.DidDetermineState += (object sender, CLRegionStateDeterminedEventArgs e) => {
                    switch(e.State)
                    {
                        case CLRegionState.Inside:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Iniside...";
                            UIAlertView testAlert = new UIAlertView ();
                            testAlert.AddButton ("OK");
                            testAlert.Title = "Entered";
                            testAlert.Message = "Region "+e.Region.ToString();
                            testAlert.Show();
                        });
                        break;

                        case CLRegionState.Outside:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Outside...";
                            UIAlertView testAlert1 = new UIAlertView ();
                            testAlert1.AddButton ("OK");
                            testAlert1.Title = "Exit";
                            testAlert1.Message = "Region "+e.Region.ToString();
                            testAlert1.Show();
                        });
                        break;

                        case CLRegionState.Unknown:
                        InvokeOnMainThread(()=>{
                            locLabel.Text = "Unknown state for region...";
                        });
                        break;
                        default:
                        break;
                    }
                };
                /* This works and gets fired */
                locManager.DidStartMonitoringForRegion += (o, e) => {
                    InvokeOnMainThread(()=>{
                        locManager.RequestState(e.Region);
                        locLabel.Text = "Now monitoring region : "+ e.Region.ToString ();
                    });
                };
                /* This doesn't get fired */
                locManager.DidVisit+=(object sender, CLVisitedEventArgs e) => {
                    InvokeOnMainThread(()=>{
                        locLabel.Text = "Did visit region...";
                        UIAlertView testAlert = new UIAlertView ();
                        testAlert.AddButton ("OK");
                        testAlert.Title = "Visited";
                        testAlert.Message = "Region "+e.Visit.Coordinate.Latitude.ToString()+" | "+e.Visit.Coordinate.Longitude.ToString();
                        testAlert.Show();
                    });
                };
                /* This doesn't get fired */
                locManager.RegionEntered += (o, e) => {
                    InvokeOnMainThread(()=>{
                        UIAlertView testAlert = new UIAlertView ();
                        testAlert.AddButton ("OK");
                        testAlert.Title = "Entered";
                        testAlert.Message = "Region "+e.Region.ToString();
                        testAlert.Show();
                        locLabel.Text = "Entered: "+e.Region.ToString();
//.........这里部分代码省略.........
开发者ID:jubinpolackal,项目名称:GeoFenceSample,代码行数:101,代码来源:MainViewController.cs

示例11: 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


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