重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
capacitor-push-notifications by capawesome-team/skills
npx skills add https://github.com/capawesome-team/skills --skill capacitor-push-notifications通过 @capacitor-firebase/messaging 插件,在 Capacitor 应用中使用 Firebase Cloud Messaging (FCM) 设置和使用推送通知。
@capacitor/push-notifications —— 它会与 @capacitor-firebase/messaging 冲突。android/、)、构建工具、框架和 依赖项。只有在无法检测到某些内容时才询问用户。广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
ios/package.json通过读取项目文件自动检测以下信息 —— 不要 询问可以推断出的信息:
平台:检查存在哪些目录 (android/、ios/)。这些就是要配置的平台。
构建工具 / 框架:检查是否存在 vite.config.ts、angular.json、webpack.config.js、next.config.js 等文件。
Capacitor 版本:从 package.json 中读取 @capacitor/core 的版本。
冲突的插件:检查 package.json 中是否存在 @capacitor/push-notifications。如果找到,警告用户必须在继续之前将其移除:
npm uninstall @capacitor/push-notifications
检查项目中是否已配置 Firebase:
android/app/google-services.json 是否存在。ios/App/App/GoogleService-Info.plist 是否存在。如果检测到的平台未配置 Firebase,请阅读 references/firebase-setup.md 并引导用户为每个缺失的平台完成 Firebase 设置。
npm install @capacitor-firebase/messaging firebase
npx cap sync
如果 android/ 不存在,则跳过此步骤。
阅读 references/android-setup.md 并应用 Android 特定的配置。
如果 ios/ 不存在,则跳过此步骤。
阅读 references/ios-setup.md 并应用 iOS 特定的配置。这包括 APNs 密钥/证书设置、AppDelegate.swift 修改以及启用功能。
如果项目目标包含 Web 平台(通过构建工具配置检测或用户确认):
阅读 references/web-setup.md 并应用 Web 特定的配置。
询问用户是否要自定义 iOS 前台通知的呈现方式。如果是,更新 capacitor.config.json 或 capacitor.config.ts:
{
"plugins": {
"FirebaseMessaging": {
"presentationOptions": ["alert", "badge", "sound"]
}
}
}
可用选项:badge、sound、alert、criticalAlert。默认值为 ["alert", "badge", "sound"]。
阅读 references/implementation.md 并将推送通知代码添加到项目中。调整导入和结构以匹配用户的框架。
实现涵盖:
询问用户要启用哪些可选功能:
对于每个选定的功能,阅读 references/implementation.md 并应用相关代码。
同步项目:
npx cap sync
阅读 references/testing.md 并引导用户通过 Firebase 控制台发送测试通知。
@capacitor/push-notifications 冲突:@capacitor-firebase/messaging 插件不能与 @capacitor/push-notifications 共存。卸载冲突的插件:npm uninstall @capacitor/push-notifications && npx cap sync。AppDelegate.swift 是否包含所需的委托方法。didRegisterForRemoteNotificationsWithDeviceToken 未被调用:确保在 Xcode 的 Signing & Capabilities 下添加了推送通知功能。检查应用的 bundle ID 是否与 Firebase 和 Apple Developer 门户中注册的匹配。google-services.json 是否位于 android/app/google-services.json。验证是否应用了 Google 服务 Gradle 插件。getToken() 失败:确保 VAPID 密钥正确。确保 firebase-messaging-sw.js 存在于域根目录。检查浏览器是否支持 Push API。null:确保在调用 getToken() 之前已调用 requestPermissions() 并返回 granted。在 iOS 上,验证设备不是模拟器(模拟器无法接收推送通知)。checkPermissions() 返回 denied:用户已永久拒绝通知权限。引导他们通过设备设置重新启用(设置 > 应用 > 通知)。requestPermissions()。较早的 Android 版本默认授予通知权限。每周安装量
59
代码仓库
GitHub 星标数
9
首次出现
8 天前
安全审计
已安装于
opencode58
gemini-cli58
amp58
cline58
github-copilot58
codex58
Set up and use push notifications in Capacitor apps using Firebase Cloud Messaging (FCM) via the @capacitor-firebase/messaging plugin.
@capacitor/push-notifications must not be installed — it conflicts with @capacitor-firebase/messaging.android/, ios/), build tools, framework, and package.json dependencies. Only ask the user when something cannot be detected.Auto-detect the following by reading project files — do not ask the user for information that can be inferred:
Platforms : Check which directories exist (android/, ios/). These are the platforms to configure.
Build tool / framework : Check for vite.config.ts, angular.json, webpack.config.js, next.config.js, etc.
Capacitor version : Read @capacitor/core version from package.json.
Conflicting plugins : Check if @capacitor/push-notifications is in . If found, warn the user it must be removed before proceeding:
Check if Firebase is already configured in the project:
android/app/google-services.json exists.ios/App/App/GoogleService-Info.plist exists.If Firebase is not configured for a detected platform, read references/firebase-setup.md and guide the user through the Firebase setup for each missing platform.
npm install @capacitor-firebase/messaging firebase
npx cap sync
Skip if android/ does not exist.
Read references/android-setup.md and apply the Android-specific configuration.
Skip if ios/ does not exist.
Read references/ios-setup.md and apply the iOS-specific configuration. This includes APNs key/certificate setup, AppDelegate.swift modifications, and enabling capabilities.
If the project targets the web (detected via build tool config or user confirmation):
Read references/web-setup.md and apply the Web-specific configuration.
Ask the user if they want to customize iOS foreground notification presentation. If yes, update capacitor.config.json or capacitor.config.ts:
{
"plugins": {
"FirebaseMessaging": {
"presentationOptions": ["alert", "badge", "sound"]
}
}
}
Available options: badge, sound, alert, criticalAlert. Default is ["alert", "badge", "sound"].
Read references/implementation.md and add the push notification code to the project. Adapt imports and structure to match the user's framework.
The implementation covers:
Ask the user which optional features to enable:
For each selected feature, read references/implementation.md and apply the relevant code.
Sync the project:
npx cap sync
Read references/testing.md and guide the user through sending a test notification via the Firebase Console.
@capacitor/push-notifications conflict: The @capacitor-firebase/messaging plugin cannot coexist with @capacitor/push-notifications. Uninstall the conflicting plugin: npm uninstall @capacitor/push-notifications && npx cap sync.AppDelegate.swift contains the required delegate methods.didRegisterForRemoteNotificationsWithDeviceToken not called: Ensure the Push Notifications capability is added in Xcode under Signing & Capabilities. Check that the app's bundle ID matches the one registered in Firebase and Apple Developer portal.google-services.json is at . Verify the Google services Gradle plugin is applied.Weekly Installs
59
Repository
GitHub Stars
9
First Seen
8 days ago
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode58
gemini-cli58
amp58
cline58
github-copilot58
codex58
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
123,700 周安装
package.jsonnpm uninstall @capacitor/push-notifications
android/app/google-services.jsongetToken() fails: Ensure the VAPID key is correct. Ensure firebase-messaging-sw.js exists at the root of the domain. Check that the browser supports the Push API.null: Ensure requestPermissions() was called and returned granted before calling getToken(). On iOS, verify the device is not a simulator (simulators cannot receive push notifications).checkPermissions() returns denied: The user has permanently denied notification permissions. Guide them to re-enable via device settings (Settings > App > Notifications).requestPermissions() must be called explicitly. Earlier Android versions grant notification permission by default.