Skip to content
Shiny.NET

Geofencing

NuGet package Shiny.AppDeviceBridge.Geofencing

The geofencing bridge gives the page permissions, the regions it monitors, and their enter and exit transitions, delivered as geofence.status events while a page is open and to background.js otherwise. It’s backed by Shiny.Geofencing.

Android, iOS, Mac Catalyst and Windows. Everywhere else every route answers 501.

The OS caps how many circles it monitors (20 on iOS, 60 on Android). For more, for polygons, or for regions such as the state or city the device is in, use Region Geofencing.

Terminal window
dotnet add package Shiny.AppDeviceBridge.Geofencing
builder.UseAppDeviceBridge(
bridge => bridge.AddGeofenceBridge(),
webApp => { /* … */ }
);
Client C# TypeScript
IGeofencesBridge AddGeofencesBridgeClient() GeofencesBridge

Monitoring survives the page: transitions reach background.js when no page is open — see Native Calls & Background.

import { GeofencesBridge } from "@shinyorg/appdevicebridge";
const geofences = new GeofencesBridge();
const { access } = await geofences.requestAccess();
if (access !== "Available") return;
await geofences.onStatus(s => console.log(s.identifier, s.state)); // "Entered" | "Exited"
await geofences.startMonitoring({
identifier: "office",
latitude: 43.6532,
longitude: -79.3832,
radiusMeters: 200,
singleUse: false,
notifyOnEntry: true,
notifyOnExit: true
});
GET/_bridge/geofences/status#

The permission state, without prompting.

C#IGeofencesBridge.GetStatusAsyncTSGeofencesBridge.getStatus
Response
200 GeofenceAccessResult
GeofenceAccessResult · 1 field
accessAccessState
POST/_bridge/geofences/access#

Requests the background location permission geofencing needs.

C#IGeofencesBridge.RequestAccessAsyncTSGeofencesBridge.requestAccess
Response
200 GeofenceAccessResult
GeofenceAccessResult · 1 field
accessAccessState
GET/_bridge/geofences/regions#

The regions being monitored.

C#IGeofencesBridge.GetRegionsAsyncTSGeofencesBridge.getRegions
Response
200 GeofenceRegion[]
GeofenceRegion · 7 fields
identifierstringNames the region; monitoring one with an identifier already in use replaces it.
latitudenumber
longitudenumber
radiusMetersnumberMust be positive.
singleUsebooleanStop monitoring after the first transition.
notifyOnEntryboolean
notifyOnExitboolean
POST/_bridge/geofences/regions#

Starts monitoring a region. Fails with 409 without permission.

C#IGeofencesBridge.StartMonitoringAsyncTSGeofencesBridge.startMonitoring
Body
application/json · GeofenceRegion
GeofenceRegion · 7 fields
identifierstringNames the region; monitoring one with an identifier already in use replaces it.
latitudenumber
longitudenumber
radiusMetersnumberMust be positive.
singleUsebooleanStop monitoring after the first transition.
notifyOnEntryboolean
notifyOnExitboolean
Response
204 No content
Errors
409Conflict
DELETE/_bridge/geofences/regions#

Stops monitoring every region.

C#IGeofencesBridge.StopAllMonitoringAsyncTSGeofencesBridge.stopAllMonitoring
Response
204 No content
DELETE/_bridge/geofences/regions/{identifier}#

Stops monitoring one region.

C#IGeofencesBridge.StopMonitoringAsyncTSGeofencesBridge.stopMonitoring
ParameterInType
identifierpathstringrequired
Response
204 No content
GET/_bridge/geofences/regions/{identifier}/state#

Whether the device is inside a monitored region now. Fails with 404 for a region not monitored.

C#IGeofencesBridge.GetStateAsyncTSGeofencesBridge.getState
ParameterInType
identifierpathstringrequired
Response
200 GeofenceStatus
GeofenceStatus · 2 fields
identifierstring
stateGeofenceState
Errors
404Not found
EVENTgeofence.status#

The device entered or left a region, while the page is open.

C#IGeofencesBridge.OnStatusAsyncTSGeofencesBridge.onStatus
Payload
GeofenceStatus
identifierstring
stateGeofenceState

JSON property names are camelCase and enums travel as their names. A ? marks a property the payload may omit;| null one that may be null.

AccessStateenum#

Where a permission stands. Reported by every bridge that needs one; the names match Shiny's own.

"Unknown""NotSupported""NotSetup""Disabled""Restricted""Denied""Available"
GeofenceRegionobject#

A circular region.

identifierstringNames the region; monitoring one with an identifier already in use replaces it.
latitudenumber
longitudenumber
radiusMetersnumberMust be positive.
singleUsebooleanStop monitoring after the first transition.
notifyOnEntryboolean
notifyOnExitboolean
GeofenceStateenum#
"Unknown""Entered""Exited"

These routes sit under AppDeviceBridgePolicies.Bridges like every other bridge: callers on this device by default. See Security.