Shiny.NET
Monitoring

Beacon monitoring is quite a bit different than ranging. Monitoring does not provide distance and has many limitations, but it works in the background. Monitoring uses beacon regions much like ranging, however, the region is all that is returned in the delegate to protect user privacy Monitoring is limited to a maximum of 20 regions on iOS. On Android & UWP, there currently isn't a limit HOWEVER the BLE scans do emit quite a number of scan packets. If you have too many, your scan will slow down your app quite a bit.

|Area|Info| |---|---| |Description|| |Service|Shiny.Beacons.IBeaconMonitorManager |NuGet|| |Static Generated Class|ShinyBeaconMonitorManager

using Microsoft.Extensions.DependencyInjection;
using Shiny;

namespace YourNamespace
{
    public class YourShinyStartup : ShinyStartup
    {
        public override void ConfigureServices(IServiceCollection services, IPlatform platform)
        { 
            
<p>services.UseBeaconMonitoring&lt;Shiny.Beacons.IBeaconMonitorDelegate&gt;();
services.UseBeaconMonitoring 
        }
    }
}

Minimum Version: 8.0

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8" ?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="com.org.yourapp" android:installLocation="preferExternal">
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.BLUETOOTH_PRIVILEGED" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
</manifest>

Minimum Version: 10

Info.plist

<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE plist PUBLIC " -//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>NSLocationAlwaysUsageDescription</key>
    <string>Say something useful here that your users will understand</string>
    <key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
    <string>Say something useful here that your users will understand</string>
    <key>NSLocationWhenInUseUsageDescription</key>
    <string>Say something useful here that your users will understand</string>
</dict>
</plist>

Gotcha

  • Scanning for any beacons always works down to specific filter sets meaning you are adding (not mixing & matching)
    1. UUID
    2. Major
    3. Minor
  • You must always have an initial filter of a UUID for ranging or monitoring
  • iOS limits the amount of beacons you are allowed to monitor to 20. This value is also shared with your geofences, so you need to think about your strategy when using beacons
  • Monitoring beacons does not allow you to see which actual beacon was detected, only the region filter is returned to your background scan. This is done by the OS to protect user privacy.

Setup

  1. Create a delegate to receive background events
using System.Threading.Tasks;
using Shiny.Beacons;


public class MyBeaconMonitorDelegate : IBeaconMonitorDelegate
{
    public async Task OnStatusChanged(BeaconRegionState newStatus, BeaconRegion region)
    {
    }
}
  1. Add the following to your Shiny Startup
using Microsoft.Extensions.DependencyInjection;
using Shiny;

namespace YourNamespace
{
    public class YourShinyStartup : ShinyStartup
    {
        public override void ConfigureServices(IServiceCollection services, IPlatform platform)
        { 
            
service.UseBeaconMonitoring<MyBeaconMonitorDelegate>();
 
        }
    }
}