benxu.AppPlatform.LocalNotification 3.0.2

dotnet add package benxu.AppPlatform.LocalNotification --version 3.0.2
                    
NuGet\Install-Package benxu.AppPlatform.LocalNotification -Version 3.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="benxu.AppPlatform.LocalNotification" Version="3.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="benxu.AppPlatform.LocalNotification" Version="3.0.2" />
                    
Directory.Packages.props
<PackageReference Include="benxu.AppPlatform.LocalNotification" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add benxu.AppPlatform.LocalNotification --version 3.0.2
                    
#r "nuget: benxu.AppPlatform.LocalNotification, 3.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package benxu.AppPlatform.LocalNotification@3.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=benxu.AppPlatform.LocalNotification&version=3.0.2
                    
Install as a Cake Addin
#tool nuget:?package=benxu.AppPlatform.LocalNotification&version=3.0.2
                    
Install as a Cake Tool

benxu.AppPlatform.LocalNotification

跨平台本地通知套件,支援 Android 與 iOS 的定時與即時通知功能。

功能特色

  • 排程通知:排程未來指定時間觸發的通知
  • 即時通知:立即顯示通知
  • 通知管理:取消、更新、查詢待處理通知
  • 通知頻道 (Android):支援 Android 8.0+ 通知頻道
  • 通知分類 (iOS):支援 iOS 通知分類與動作按鈕
  • 權限管理:內建權限請求與檢查功能
  • 深度連結:點擊通知後導航至指定頁面
  • 開機重排程:裝置重啟後自動重新排程通知

快速開始

安裝

使用 Bootstrap 註冊服務(推薦):

builder.UseAppPlatform(options =>
{
    options.UseLocalNotification(notification =>
    {
        notification.DefaultChannelId = "my_app_notifications";
        notification.DefaultChannelName = "App Notifications";
        notification.DefaultChannelDescription = "應用程式通知";
        notification.AutoRequestPermission = true;
    });
});

基本使用

@inject ILocalNotificationService NotificationService

// 立即發送通知
var notification = new LocalNotification
{
    Title = "提醒",
    Body = "這是一條測試通知!",
    UseDefaultSound = true
};
await NotificationService.ShowNotificationAsync(notification);

// 排程 10 分鐘後的通知
var scheduledTime = DateTime.Now.AddMinutes(10);
await NotificationService.ScheduleNotificationAsync(notification, scheduledTime);

平台設定

⚠️ 重要:請務必完成以下平台設定,否則通知將無法正常運作!

詳細設定請參閱:LocalNotification 整合指南

Android 必要設定

  1. AndroidManifest.xml 新增權限:

    <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
    <uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
    <uses-permission android:name="android.permission.USE_EXACT_ALARM" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    
  2. MainActivity.cs 動態請求權限(Android 13+)

iOS 必要設定

  1. AppDelegate.cs 設置 UNUserNotificationCenterDelegate

API 參考

ILocalNotificationService

方法 說明
InitializeAsync() 初始化服務
ScheduleNotificationAsync(notification, scheduledTime) 排程通知
ShowNotificationAsync(notification) 立即顯示通知
CancelNotificationAsync(id) 取消指定通知
CancelAllNotificationsAsync() 取消所有通知
HasPermissionAsync() 檢查權限
RequestPermissionAsync() 請求權限
OpenNotificationSettingsAsync() 開啟系統通知設定
CanScheduleExactAlarmsAsync() 檢查精確鬧鐘權限 (Android)
OpenExactAlarmSettingsAsync() 開啟精確鬧鐘設定 (Android)

LocalNotification 屬性

屬性 類型 說明
Id int 通知 ID
ReferenceId string? 業務關聯 ID(如 Task ID)
Title string 標題
Body string 內容
ChannelId string? 頻道 ID (Android)
CategoryId string? 分類 ID (iOS)
DeepLink string? 深度連結 URL
UseDefaultSound bool 使用預設音效
Data Dictionary<string, string> 自訂資料

注意事項

  • Android 13+:需要 POST_NOTIFICATIONS 權限
  • Android 12+:需要 SCHEDULE_EXACT_ALARM 權限才能精確排程
  • iOS:最多支援 64 個待排程通知
  • 裝置重啟:建議在 App 啟動時重新排程通知

License

MIT License

Product Compatible and additional computed target framework versions.
.NET net10.0-android36.0 is compatible.  net10.0-ios26.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on benxu.AppPlatform.LocalNotification:

Package Downloads
benxu.AppPlatform.MAUI.Bootstrap

Bootstrap package for benxu App Platform. Provides fluent API for one-line service registration and lifecycle management.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.2 83 1/17/2026