本文整理汇总了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");
}
示例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);
}
示例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 ();
}
示例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);
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}