maui-push-notifications

End-to-end guide for adding push notifications to .NET MAUI apps. Covers Firebase Cloud Messaging (Android), Apple Push Notification Service (iOS), using Azure Notification Hubs as a cross-platform broker, an ASP.NET Core backend API, and MAUI client integration on each platform including device registration and notification token handling. Applicable to push notifications, FCM, APNS, Azure Notification Hubs, device registration, remote notifications, and sending push messages. Not for local/scheduled notifications (use maui-local-notifications), general permission handling (use maui-permissions), or background tasks without notifications (use maui-app-lifecycle).

Last repository push
GitHub Stars
181
Forks
21
Issues / PRs
1

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "maui-push-notifications" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-06c236df16f2e620efda8fa31b14899373fdf16c8a3fb3c9f3faae5b743f8415. Verify the upstream source and version against https://github.com/davidortinau/maui-skills before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

github.com

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

End-to-end guide for adding push notifications to .NET MAUI apps. Covers Firebase Cloud Messaging (Android), Apple Push Notification Service (iOS), using Azure Notification Hubs as a cross-platform broker, an ASP.NET Core backend API, and MAUI client integration on each platform including device registration and notification token handling. Applicable to push notifications, FCM, APNS, Azure Notification Hubs, device registration, remote notifications, and sending push messages. Not for local/scheduled notifications (use maui-local-notifications), general permission handling (use maui-permissions), or background tasks without notifications (use maui-app-lifecycle).

0 Downloads

Introduction source: third_party · davidortinau · 0.0.1 Reference

SkillPi interpretation

Tasks
`HttpClient.BaseAddress` **must** end with `/`. Without it, relative URI resolution silently breaks.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: maui-push-notifications
description: >
  End-to-end guide for adding push notifications to .NET MAUI apps.
  Covers Firebase Cloud Messaging (Android), Apple Push Notification Service (iOS),
  Azure Notification Hubs as the cross-platform broker, an ASP.NET Core backend API,
  and the MAUI client wiring on every platform.
  USE FOR: "push notification", "FCM", "APNS", "Firebase Cloud Messaging",
  "Azure Notification Hubs", "device registration", "remote notification",
  "send push notification", "notification token".
  DO NOT USE FOR: local/scheduled notifications (use maui-local-notifications),
  general permission handling (use maui-permissions), or background tasks without notifications (use maui-app-lifecycle).

Push Notifications — Gotchas & Best Practices

Troubleshooting Table

Issue Cause Fix
Token changes every debug run (Android) Debug builds regenerate Firebase tokens Always re-register in OnNewToken
HttpClient requests fail silently BaseAddress missing trailing / Ensure endpoint ends with /
iOS push won't arrive on simulator Simulators don't support APNS Use a physical iOS device
No notifications on Android 13+ POST_NOTIFICATIONS required (API 33+) Call RequestPermissions in OnCreate
Notification channel missing (API 26+) Android requires explicit channel creation Create channel before sending
SendNotificationAsync throws for >20 tags Azure NH tag expression limit Batch tags in groups of 20
422 on device registration Platform string mismatch Use "fcmv1" (not "gcm") and "apns"
Token empty at RegisterAsync Race condition on cold start Guard with IsNullOrWhiteSpace check

Critical Gotchas

⚠️ BaseAddress trailing slash

HttpClient.BaseAddress must end with /. Without it, relative URI resolution silently breaks.

// ❌ Relative URIs resolve incorrectly
_http = new HttpClient { BaseAddress = new Uri("https://example.com") };

// ✅ Trailing slash required
_http = new HttpClient { BaseAddress = new Uri("https://example.com/") };

⚠️ Android: Always re-register on token refresh

Firebase tokens regenerate frequently in debug builds. If you skip OnNewToken, the backend holds a stale token and pushes silently fail.

// ❌ Only registering once at startup
// (token may change later without re-registration)

// ✅ Always re-register in OnNewToken
public override void OnNewToken(string token)
{
    var svc = IPlatformApplication.Current?.Services.GetService<IPushNotificationService>();
    if (svc is null) return;
    svc.Token = token;
    _ = svc.RegisterAsync();
}

⚠️ Android 13+ requires POST_NOTIFICATIONS permission

Without explicitly requesting POST_NOTIFICATIONS on API 33+, notifications are silently dropped.

⚠️ Azure NH tag expression limit: 20 tags

SendNotificationAsync throws if a tag expression references more than 20 tags. Batch into chunks:

// ✅ Batch tags to stay under the limit
var batches = request.Tags.Chunk(20);
foreach (var batch in batches)
{
    var tagExpr = string.Join(" || ", batch);
    await _hub.SendFcmV1NativeNotificationAsync(payload, tagExpr, ct);
}

⚠️ Use "fcmv1" not "gcm"

The legacy "gcm" platform string causes 422 errors on device registration. Always use "fcmv1" for Android and "apns" for iOS.

⚠️ iOS simulators cannot receive push notifications

APNS only works on physical iOS devices. Simulators silently ignore push registrations.

Platform Checklist

Android

  • [ ] google-services.json in Platforms/Android/ with <GoogleServicesJson> in .csproj
  • [ ] Xamarin.Firebase.Messaging NuGet package added (Android-only condition)
  • [ ] POST_NOTIFICATIONS permission requested on API 33+
  • [ ] Notification channel created before first notification (API 26+)
  • [ ] OnNewToken always calls RegisterAsync
  • [ ] FirebaseMessagingService registered in manifest with MESSAGING_EVENT intent filter

iOS

  • [ ] Push Notifications capability enabled in Apple Developer portal
  • [ ] APNs key (.p8) uploaded to Azure Notification Hub
  • [ ] Entitlements.plist with aps-environment set to development or production
  • [ ] CodesignEntitlements set in .csproj
  • [ ] RegisterForRemoteNotifications called on main thread after authorization grant
  • [ ] Device token converted to lowercase hex string (no dashes)

Backend

  • [ ] Azure Notification Hub configured with FCM V1 JSON and APNS key
  • [ ] BaseAddress ends with trailing /
  • [ ] Tag expressions batched in groups of ≤20
  • [ ] Platform strings: "fcmv1" and "apns" (not legacy values)

Architecture Overview

MAUI app → ASP.NET Core backend → Azure Notification Hub → FCM / APNS → device

See references/push-notifications-api.md for full implementation templates.

Current listing version

0.0.1

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value85/100

Highlights

  • .NET MAUI 推送通知端到端解决方案,覆盖 Android/iOS/后端全栈集成
  • 提供详尽的 Troubleshooting Table 和 Platform Checklist,显著降低开发者踩坑风险
Trigger Precision95/100

Highlights

  • 触发词完整且边界清晰,明确排除本地通知、权限处理等无关场景
  • USE FOR/DO NOT USE FOR 结构有效防止误触发
Structure and Standards90/100

Areas to improve

  • description写错位置 Reported severity: Minor

    description 内容写在 frontmatter 内 skill_body 中,未在顶层单独字段

    Recommendation: 建议将 description 移至顶层元数据字段,保持与平台规范一致

Highlights

  • 文档结构清晰,含故障排查表、关键陷阱、平台检查清单和架构图
  • 代码示例具体,frontmatter 完整,单文件长度合理
Execution Reliability90/100

Areas to improve

  • 引用文件缺失 Reported severity: Major

    SKILL.md 引用了 references/push-notifications-api.md 文件但未传入

    Recommendation: 请补充 references/push-notifications-api.md 文件或移除引用链接

Highlights

  • 工具来源明确(Firebase、Azure、.NET MAUI),参数正确(fcmv1/apns)
  • 覆盖主要异常场景(token刷新、权限请求、tag限制、BaseAddress斜杠)并提供修复方案
Evidence Verifiability (mean of the first four)90/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

Domains or addresses referenced in the document

These addresses may be documentation links or examples, not an approved network allowlist. Verify actual destinations and outgoing data before use.

  • example.com

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.