Thinktecture.Blazor.Badging
1.0.0
See the version list below for details.
dotnet add package Thinktecture.Blazor.Badging --version 1.0.0
NuGet\Install-Package Thinktecture.Blazor.Badging -Version 1.0.0
<PackageReference Include="Thinktecture.Blazor.Badging" Version="1.0.0" />
paket add Thinktecture.Blazor.Badging --version 1.0.0
#r "nuget: Thinktecture.Blazor.Badging, 1.0.0"
// Install Thinktecture.Blazor.Badging as a Cake Addin #addin nuget:?package=Thinktecture.Blazor.Badging&version=1.0.0 // Install Thinktecture.Blazor.Badging as a Cake Tool #tool nuget:?package=Thinktecture.Blazor.Badging&version=1.0.0
Thinktecture.Blazor.Badging
Introduction
A Blazor wrapper for the Badging API.
The Badging API allows you to share a text, title, URL, or files with another application installed on the user's system via the share functionality provided by the operating system.
Getting started
Prerequisites
You need .NET 6.0 or newer to use this library.
Platform support
Platform support for Badging API
Installation
You can install the package via NuGet with the Package Manager in your IDE or alternatively using the command line:
dotnet add package Thinktecture.Blazor.Badging
Usage
The package can be used in Blazor WebAssembly projects.
Imports
You need to import the package to use it on your pages. This can be achieved by adding the following using statement to _Imports.razor
:
@using Thinktecture.Blazor.Badging
Add to service collection
To make the BadgingService available on all pages, register it at the IServiceCollection in Program.cs
before the host is built:
builder.Services.AddBadgingService();
Checking for browser support
Before using the Badging API, you should first test if the API is supported on the target platform by calling the IsSupportedAsync()
method.
This method returns a boolean to indicate whether the Badging API is supported or not.
var isSupported = await badgingService.IsSupportedAsync();
if (isSupported)
{
// enable badging feature
}
else
{
// use fallback mechanism or hide/disable feature
}
Internally, this method tests for the presence of the setAppBadge()
and clearAppBadge()
methods on the navigator
object of the target browser.
Set app badge
The SetAppBadgeAsync()
method sets a badge on the current app's icon.
If a value is passed to this method, it will be set as the value of the badge:
await badgingService.SetAppBadgeAsync(3);
When omitting the contents
parameter, a generic badge will be shown, as defined by the platform.
await badgingService.SetAppBadgeAsync();
Clear app badge
The ClearAppBadgeAsync()
method clears the badge on the current app's icon:
await badgingService.ClearAppBadgeAsync();
Related articles
- setAppBadge() Documentation on MDN
- clearAppBadge() Documentation on MDN
- Blog post on web.dev
- Browser support on caniuse.com
Acknowledgements
Thanks to Kristoffer Strube who provides a Blazor wrapper for the File System Access API. This library is inspired by Kristoffer's implementation and project setup.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
-
net6.0
- Microsoft.AspNetCore.Components.Web (>= 6.0.9)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.