@capacitor/push-notifications
The Push Notifications API provides access to native push notifications.
Install
npm install @capacitor/push-notifications
npx cap sync
iOS
On iOS you must enable the Push Notifications capability. See Setting Capabilities for instructions on how to enable the capability.
After enabling the Push Notifications capability, add the following to your app's AppDelegate.swift
:
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: deviceToken)
}
func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) {
NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error)
}
Android
The Push Notification API uses Firebase Cloud Messaging SDK for handling notifications. See Set up a Firebase Cloud Messaging client app on Android and follow the instructions for creating a Firebase project and registering your application. There is no need to add the Firebase SDK to your app or edit your app manifest - the Push Notifications provides that for you. All that is required is your Firebase project's google-services.json
file added to the module (app-level) directory of your app.
Android 13 requires a permission check in order to receive push notifications. You are required to call checkPermissions()
and requestPermissions()
accordingly, when targeting SDK 33.
From Android 15 onwards, users can install an app in the Private space. Users can lock their private space at any time, which means that push notifications are not shown until the user unlocks it.
It is not possible to detect if an app is installed in the private space. Therefore, if your app shows any critical notifications, inform your users to avoid installing the app in the private space.
For more information about the behavior changes of your app related to the private space, refer to Android documentation.
Variables
This plugin will use the following project variables (defined in your app's variables.gradle
file):
firebaseMessagingVersion
version ofcom.google.firebase:firebase-messaging
(default:24.1.0
)