{"id":16934,"date":"2015-02-23T14:48:15","date_gmt":"2015-02-23T19:48:15","guid":{"rendered":"http:\/\/blog.xamarin.com\/?p=16934"},"modified":"2015-02-23T14:48:15","modified_gmt":"2015-02-23T19:48:15","slug":"adding-real-world-context-with-estimote-beacons-and-stickers","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/adding-real-world-context-with-estimote-beacons-and-stickers\/","title":{"rendered":"Adding Real-world Context with Estimote Beacons and Stickers"},"content":{"rendered":"<p>\t\t\t\tIt&#8217;s no secret that iBeacons have created a buzz in the development community. Leveraging these Bluetooth Smart devices enables developers to add contextual awareness to their mobile apps with just a few lines of code. iBeacons were everywhere at Evolve 2014, including at the forefront of the <a href=\"\/create-your-own-scavenger-hunt-with-evolve-quest\/\" title=\"Evolve Scavenger Hunt\">Evolve Quest scavenger hunt<\/a> and <a href=\"https:\/\/github.com\/xamarin\/mini-hacks\" title=\"Xamarin Mini-Hacks\">the conference mini-hacks<\/a>, as well as taking the main stage for an <a href=\"https:\/\/www.youtube.com\/watch?v=YYTa_Rv5Pz4\" title=\"Xamarin Evolve 2014: iBeacons &amp; Location Awareness\">in-depth session<\/a>. <\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/sticker_bike-300x202.png\" alt=\"sticker_bike\" width=\"200\" class=\"alignright size-medium wp-image-16942\" \/><a href=\"http:\/\/www.estimote.com\" title=\"Estimote\">Estimote<\/a>, a leader in the iBeacon space, recently introduced Estimote Stickers, a low-powered device to go alongside their traditional beacons. Stickers can be attached to almost anything and turn any everyday item into a &#8220;nearable&#8221; &#8211; a smart object that can transmit data about its location, motion, temperature, and environment to nearby apps and devices. Today, we&#8217;re pleased to announce the Estimote SDK for iOS, <a href=\"http:\/\/components.xamarin.com\/view\/estimotesdkios\" title=\"Estimote SDK for iOS\">available on the Xamarin Component Store<\/a>, enabling developers to easily detect Beacons and Estimote Stickers with a beautiful C# API that includes events and async\/await support.<\/p>\n<h2>Detecting Nearables<\/h2>\n<p>Nearables have a new, simplified API. Each Nearable has a specific <code>NearableType<\/code> that can be used to detect, for example, Car, Dog, or Bike. You can decide to range for a specific type or all nearby Nearable devices.<\/p>\n<p>Let&#8217;s see how easy it is to get up and running with Nearables by scanning for all Nearables that are close by.<\/p>\n<h3>Install the Estimote SDK for iOS<\/h3>\n<p>The very first task is to set up a new Xamarin.iOS project and add the Estimote SDK for iOS from the component store. <\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/2015-02-19_1313-1024x335.png\" alt=\"2015-02-19_1313\" width=\"600\" class=\"aligncenter size-large wp-image-16945\" \/><\/p>\n<p>In addition to the SDK, you must specify <strong>NSLocationAlwaysUsageDescription<\/strong> or <strong>NSLocationWhenInUseUsageDescription<\/strong> in your Info.plst file with a description that will be prompted to your users, since iBeacons use CoreLocation functionality.<\/p>\n<h3>Setting Up App ID<\/h3>\n<p>When you log in to your Estimote Cloud, you are able to manage all of your Beacons and Stickers in addition to creating API keys for your mobile apps. Once you have an app set up in the Estimote Cloud, you can config the app in your AppDelegate&#8217;s <code>OnFinishedLaunching<\/code> method:<\/p>\n<pre class=\"lang:csharp decode:true\">\nConfig.SetupAppID (&quot;&lt;appId from cloud&gt;&quot;, &quot;&lt;appToken from cloud&gt;&quot;);\n<\/pre>\n<p>While not required, it&#8217;s recommended to set up your app ID so that the SDK can now communicate with the Estimote Cloud to pull in unique attributes. <\/p>\n<h3>Ranging Nearables<\/h3>\n<p>Using the new <code>NearableManager<\/code> you can easily range for Nearables by subscribing to the RangedNearables event.<\/p>\n<pre class=\"lang:csharp decode:true\">\nNearableManager manager;\npublic override void ViewDidLoad ()\n{\n  base.ViewDidLoad ();\n  manager = new NearableManager ();\n  manager.RangedNearables += (sender, e) =&gt; {\n    \/\/Nearables detected, load into TableView or pop up alert\n    new UIAlertView(&quot;Nearables Found&quot;, &quot;Just found: &quot; + e.Nearables.Length + &quot; nearables.&quot;, null, &quot;OK&quot;).Show();\n  };\n\n  \/\/Specify the type of Nearable to range for. In this instance return All types.\n  manager.StartRanging (NearableType.All);\n}\n<\/pre>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/nearablesdetected-493x1024.png\" alt=\"Estimote Nearables Detected\" width=\"275\" class=\"aligncenter size-large wp-image-16954\" \/><\/p>\n<p>The real power of Nearables is the additional attributes that are received when they are detected, such as their temperature, orientation, acceleration, and more. As an example, you could easily use these attributes to detect a Bike Nearable in motion for over 45 minutes and prompt your user to perhaps take a break.<\/p>\n<pre class=\"lang:csharp decode:true\">\nNearableManager nearableManager;\npublic override void ViewDidLoad ()\n{\t\t\n  var identifier = &quot;94064be7a9d7c189&quot;; \/\/Identifier ranged earlier\n  var durationThreshold = 45 * 60; \/\/45 minutes\n\n  nearableManager = new NearableManager ();\n\n  nearableManager.RangedNearable += (sender, e) =&gt; {\n    var bike = e.Nearable;\n    if(bike.IsMoving &amp;&amp; bike.CurrentMotionStateDuration &gt; durationThreshold) {\n      Console.WriteLine(&quot;Bike is moving and has been in motion for over 45 minutes!&quot;);\n    }\n  };\n\n  nearableManager.StartRanging(identifier);\n}\n<\/pre>\n<h2>Triggers and Rules<\/h2>\n<p>In addition to ranging and monitoring Nearables, there is an advanced trigger system in the Estimote SDK that enables you to specify several rules that would trigger a notification. Let&#8217;s say you want to be notified every time a Nearable changes orientation and is laid down in a horizontal position. You would simply create a <code>OrientationRule<\/code> and use the <code>TriggerManager<\/code> to wait for the Nearable&#8217;s state to change.<\/p>\n<pre class=\"lang:csharp decode:true\">\nTriggerManager triggerManager;\npublic override void ViewDidLoad ()\n{\n  var rule = OrientationRule.OrientationEquals (NearableOrientation.Horizontal, NearableType.Shoe);\n  var trigger = new Trigger (new Rule[]{ rule }, &quot;TriggerId&quot;);\n\n  triggerManager = new TriggerManager ();\n  triggerManager.StartMonitoring (trigger);\n  triggerManager.ChangedState += HandleTriggerChangedState;\n  triggerManager.ChangedState += (sender, e) =&gt; {\n    Console.Log(&quot;Shoe nearable has been placed horizontal&quot;);\n  };\n}\n<\/pre>\n<p>More complex rules can be configured that are based on DateTime, temperature, proximity, and more.<\/p>\n<h2>Enhanced C# Beacon API<\/h2>\n<p>Xamarin.iOS has been able to detect iBeacons from any vendor since the feature was introduced in iOS 7 in CoreLocation. However, the Estimote SDK greatly simplifies the tasks of requesting and a simplified API for ranging and monitoring for beacons. In addition, if you are using Estimote Beacons you can tap into advanced features, such as their accelerometer.<\/p>\n<p><img decoding=\"async\" src=\"\/wp-content\/uploads\/sites\/44\/2019\/04\/0001125_estimote-beacons.jpeg\" alt=\"0001125_estimote-beacons\" width=\"560\" height=\"191\" class=\"aligncenter size-full wp-image-16951\" \/><\/p>\n<h2>Learn More<\/h2>\n<p>The <a href=\"http:\/\/components.xamarin.com\/view\/estimotesdkios\" title=\"Estimote SDK for iOS\">Estimote SDK for iOS<\/a> has plenty of great samples for both Nearables and Beacons for you to start out with, including a full Getting Started Guide. In addition, Estimote has <a href=\"http:\/\/estimote.github.io\/iOS-SDK\/\" title=\"Estimote SDK Reference\">SDK reference documentation<\/a> and a <a href=\"https:\/\/community.estimote.com\/hc\/en-us\" title=\"Estimote Developer Portal\">developer portal<\/a> with more information.  <\/p>\n<p>If you are interested in adding iBeacon functionality to your Xamarin.Android apps, be sure to check the <a href=\"http:\/\/components.xamarin.com\/?search=beacon\" title=\"Android Beacon Libraries\">component store for multiple libraries<\/a> that you can take advantage of. <\/p>\n<p><a href=\"http:\/\/forums.xamarin.com\/discussion\/33779\" title=\"Discuss on Forums\"><em>Discuss this post on the Xamarin Forums.<\/em><\/a>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s no secret that iBeacons have created a buzz in the development community. Leveraging these Bluetooth Smart devices enables developers to add contextual awareness to their mobile apps with just a few lines of code. iBeacons were everywhere at Evolve 2014, including at the forefront of the Evolve Quest scavenger hunt and the conference mini-hacks, [&hellip;]<\/p>\n","protected":false},"author":544,"featured_media":39167,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[4],"class_list":["post-16934","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-xamarin-platform"],"acf":[],"blog_post_summary":"<p>It&#8217;s no secret that iBeacons have created a buzz in the development community. Leveraging these Bluetooth Smart devices enables developers to add contextual awareness to their mobile apps with just a few lines of code. iBeacons were everywhere at Evolve 2014, including at the forefront of the Evolve Quest scavenger hunt and the conference mini-hacks, [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/16934","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/544"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=16934"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/16934\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media\/39167"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=16934"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=16934"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=16934"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}