push 代码规划
- 作者仓库星标 245
- 作者仓库 useful-ai-prompts
Push Notification Setup
Table of Contents
Overview
Implement comprehensive push notification systems for iOS and Android applications using Firebase Cloud Messaging and native platform services.
When to Use
- Sending real-time notifications to users
- Implementing user engagement features
- Deep linking from notifications to specific screens
- Handling silent/background notifications
- Tracking notification analytics
Quick Start
Minimal working example:
import messaging from "@react-native-firebase/messaging";
import { Platform } from "react-native";
export async function initializeFirebase() {
try {
if (Platform.OS === "ios") {
const permission = await messaging().requestPermission();
if (permission === messaging.AuthorizationStatus.AUTHORIZED) {
console.log("iOS notification permission granted");
}
}
const token = await messaging().getToken();
console.log("FCM Token:", token);
await saveTokenToBackend(token);
messaging().onTokenRefresh(async (newToken) => {
await saveTokenToBackend(newToken);
});
messaging().onMessage(async (remoteMessage) => {
console.log("Notification received:", remoteMessage);
showLocalNotification(remoteMessage);
});
// ... (see reference guides for full implementation)
Reference Guides
Detailed implementations in the references/ directory:
| Guide | Contents |
|---|---|
| Firebase Cloud Messaging Setup | Firebase Cloud Messaging Setup |
| iOS Native Setup with Swift | iOS Native Setup with Swift |
| Android Setup with Kotlin | Android Setup with Kotlin |
| Flutter Implementation | Flutter Implementation |
Best Practices
✅ DO
- Request permission before sending notifications
- Implement token refresh handling
- Use different notification channels by priority
- Validate tokens regularly
- Track notification delivery
- Implement deep linking
- Handle notifications in all app states
- Use silent notifications for data sync
- Store tokens securely on backend
- Provide user notification preferences
- Test on real devices
❌ DON'T
- Send excessive notifications
- Send without permission
- Store tokens insecurely
- Ignore notification failures
- Send sensitive data in payload
- Use notifications for spam
- Forget to handle background notifications
- Make blocking calls in handlers
- Send duplicate notifications
- Ignore user preferences
- 流狐分类
- 通用
- 作者声明 Agent
- 未找到明确声明;不据此推断已兼容或已测试
- 静态检查
- 88 / 100 · 启发式扫描,不代表运行安全
- 作者 / 版本 / 许可
- @aj-geddes · 未声明 license
- 流狐 Token 估算
- 低消耗
- 流狐接入估算
- 即装即用
- 是否需要外部 API Key
- 未发现要求
- 检测到的系统要求
- 未声明
- 底层运行要求
- 未声明
- 检测到的文件与系统行为
-
- 只读
- 允许写入 / 修改
- 检测到的网络行为
- 仅限本地
- 安装命令数
- 无(仅作为资料)
档案由构建时根据 SKILL.md 与安装命令自动衍生,可能与作者实际意图存在差异。
需要注意: 未限定 allowed-tools,默认拥有全部工具权限。
作者没有在当前 SKILL.md 中定义固定输出样例。 Overview When to Use Quick Start
Implement comprehensive push notification systems for iOS and Android applications using Firebase Cloud Messaging and native platform services.
Sending real-time notifications to users Implementing user engagement features Deep linking from notifications to specific screens
Minimal working example:
Detailed implementations in the references/ directory: Guide · Contents Firebase Cloud Messaging Setup · Firebase Cloud Messaging Setup
Best Practices
# Push Notification Setup
## Table of Contents
- [Overview](#overview)
- [When to Use](#when-to-use)
- [Quick Start](#quick-start)
- [Reference Guides](#reference-guides)
- [Best Practices](#best-practices)
## Overview
Implement comprehensive push notification systems for iOS and Android applications using Firebase Cloud Messaging and native platform services.
## When to Use
- Sending real-time notifications to users
- Implementing user engagement features
- Deep linking from notifications to specific screens
- Handling silent/background notifications
- Tracking notification analytics
## Quick Start
Minimal working example:
```javascript
import messaging from "@react-native-firebase/messaging";
import { Platform } from "react-native";
export async function initializeFirebase() {
try {
if (Platform.OS === "ios") {
const permission = await messaging().requestPermission();
if (permission === messaging.AuthorizationStatus.AUTHORIZED) {
console.log("iOS notification permission granted");
}
}
const token = await messaging().getToken();
console.log("FCM Token:", token);
await saveTokenToBackend(token);
messaging().onTokenRefresh(async (newToken) => {
await saveTokenToBackend(newToken);
});
messaging().onMessage(async (remoteMessage) => {
console.log("Notification received:", remoteMessage);
showLocalNotification(remoteMessage);
});
// ... (see reference guides for full implementation)
```
## Reference Guides
Detailed implementations in the `references/` directory:
| Guide | Contents |
|---|---|
| [Firebase Cloud Messaging Setup](references/firebase-cloud-messaging-setup.md) | Firebase Cloud Messaging Setup |
… 作者原文负责流程事实;流狐只索引当前章节、要点、文件与命令。
章节 -> Table of Contents → Overview → When to Use → Quick Start → Reference Guides → Best Practices
要点 -> // ...
文件/命令 -> references/ · silent/background · react-native-firebase/messaging · references/firebase-cloud-messaging-setup.md · references/ios-native-setup-with-swift.md · references/android-setup-with-kotlin.md · references/flutter-implementation.md
内容 SHA-256 -> 27c377018185
方法与流程
适用与边界
原文中的明确线索
references/、silent/background、react-native-firebase/messaging、references/firebase-cloud-messaging-setup.md、references/ios-native-setup-with-swift.md、references/android-setup-with-kotlin.md、references/flutter-implementation.md