benxu.AppPlatform.Firebase.Fcm
2.0.0
See the version list below for details.
dotnet add package benxu.AppPlatform.Firebase.Fcm --version 2.0.0
NuGet\Install-Package benxu.AppPlatform.Firebase.Fcm -Version 2.0.0
<PackageReference Include="benxu.AppPlatform.Firebase.Fcm" Version="2.0.0" />
<PackageVersion Include="benxu.AppPlatform.Firebase.Fcm" Version="2.0.0" />
<PackageReference Include="benxu.AppPlatform.Firebase.Fcm" />
paket add benxu.AppPlatform.Firebase.Fcm --version 2.0.0
#r "nuget: benxu.AppPlatform.Firebase.Fcm, 2.0.0"
#:package benxu.AppPlatform.Firebase.Fcm@2.0.0
#addin nuget:?package=benxu.AppPlatform.Firebase.Fcm&version=2.0.0
#tool nuget:?package=benxu.AppPlatform.Firebase.Fcm&version=2.0.0
benxu.AppPlatform.Firebase.Fcm
Firebase Cloud Messaging (FCM) 實作套件 - 使用官方/社群套件 (Plugin.Firebase.CloudMessaging) 提供推播通知服務與 Deep Link 路由功能。
特色
- 真實 FCM 整合:使用
Plugin.Firebase.CloudMessaging進行原生 API 呼叫。 - 推播通知接收:支援前景與背景通知接收。
- Deep Link 路由:內建 Deep Link 解析與導航機制。
- Device Token 管理:自動取得與更新 FCM Token。
- 權限管理:封裝各平台的通知權限請求邏輯。
支援平台
- ✅ Android (完整支援)
- ✅ iOS (完整支援)
安裝
安裝套件:
dotnet add package benxu.AppPlatform.Firebase.Fcm平台設定:
- Android: 需設定
AndroidManifest.xml權限與google-services.json。 - iOS: 需設定
Info.plist與GoogleService-Info.plist,並啟用 Push Notifications Capability。
- Android: 需設定
使用方式
1. 註冊服務
在 MauiProgram.cs 中:
using benxu.AppPlatform.MAUI.Bootstrap.Extensions;
builder.UseAppPlatform(options =>
{
options.UseFcm(fcm =>
{
fcm.EnableForegroundNotifications = true;
fcm.DefaultNotificationChannelId = "my_channel";
fcm.AutoSubscribeTopics = new List<string> { "global" };
});
});
2. 應用程式初始化
在 App.razor 或主要 Layout 初始化並訂閱事件:
@inject IPushNotificationService PushService
@code {
protected override async Task OnInitializedAsync()
{
PushService.NotificationReceived += OnNotificationReceived;
PushService.NotificationTapped += OnNotificationTapped;
await PushService.InitializeAsync();
}
// ... 事件處理
}
3. Deep Link 路由
@inject IDeepLinkRouter DeepLinkRouter
// 註冊路由
DeepLinkRouter.RegisterRouteHandler("myapp", async (deepLink) =>
{
if (deepLink.Host == "product")
{
var id = deepLink.QueryParameters.GetValueOrDefault("id");
Navigation.NavigateTo($"/products/{id}");
return Result.Success();
}
return Result.Failure("Unknown route");
});
注意事項
- 模擬模式:目前尚未實作,請使用真實裝置測試推播功能。
- iOS 權限:iOS 模擬器無法接收遠端推播,必須使用實機測試。
依賴項目
Plugin.Firebase.CloudMessagingbenxu.AppPlatform.Core
授權
MIT License - Copyright (c) 2025 benxu
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0-android35.0 is compatible. net9.0-ios18.0 is compatible. net10.0-android was computed. net10.0-ios was computed. |
-
net9.0-android35.0
- benxu.AppPlatform.Core (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.5)
- Microsoft.Maui.Controls (>= 9.0.82)
- Plugin.Firebase.CloudMessaging (>= 3.1.0)
- Xamarin.AndroidX.Activity (>= 1.10.1.1)
- Xamarin.AndroidX.Activity.Ktx (>= 1.10.1.1)
- Xamarin.AndroidX.Collection (>= 1.5.0.1)
- Xamarin.AndroidX.Collection.Jvm (>= 1.5.0.1)
- Xamarin.AndroidX.Collection.Ktx (>= 1.5.0.1)
- Xamarin.Build.Download (>= 0.11.4)
-
net9.0-ios18.0
- benxu.AppPlatform.Core (>= 2.0.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.5)
- Microsoft.Extensions.Logging.Abstractions (>= 9.0.5)
- Microsoft.Maui.Controls (>= 9.0.82)
- Plugin.Firebase.CloudMessaging (>= 3.1.0)
- Xamarin.Build.Download (>= 0.11.4)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on benxu.AppPlatform.Firebase.Fcm:
| Package | Downloads |
|---|---|
|
benxu.AppPlatform.MAUI.Bootstrap
Bootstrap package for benxu App Platform. Provides fluent API for one-line service registration and lifecycle management. |
|
|
benxu.AppPlatform.Notification
跨平台通知服務套件,提供 Android 和 iOS 的推播通知、本地通知管理功能,整合 Firebase Cloud Messaging (FCM) 服務,支援通知排程、通知歷程記錄與本地儲存,適用於 .NET MAUI Blazor 應用程式開發。 |
GitHub repositories
This package is not used by any popular GitHub repositories.