Skip to content

Commit

Permalink
docs: update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
RaddishIoW committed Apr 5, 2023
1 parent 7081e8c commit 8248d31
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 15 deletions.
44 changes: 29 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func application(_ application: UIApplication, didFailToRegisterForRemoteNotific

## Android

The Push Notification API uses [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) SDK for handling notifications. See [Set up a Firebase Cloud Messaging client app on Android](https://firebase.google.com/docs/cloud-messaging/android/client) 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.
The Push Notification API uses [Firebase Cloud Messaging](https://firebase.google.com/docs/cloud-messaging) SDK for handling notifications. See [Set up a Firebase Cloud Messaging client app on Android](https://firebase.google.com/docs/cloud-messaging/android/client) 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.

### Variables

Expand Down Expand Up @@ -88,7 +88,7 @@ In `capacitor.config.json`:
In `capacitor.config.ts`:

```ts
/// <reference types="@capacitor/push-notifications" />
/// <reference types="@haylltd/capacitor-push-notifications" />

import { CapacitorConfig } from '@capacitor/cli';

Expand All @@ -110,17 +110,21 @@ export default config;
</docgen-config>

## Silent Push Notifications / Data-only Notifications

#### iOS

This plugin does not support iOS Silent Push (Remote Notifications). We recommend using native code solutions for handling these types of notifications, see [Pushing Background Updates to Your App](https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/pushing_background_updates_to_your_app).

#### Android
This plugin does support data-only notifications, but will NOT call `pushNotificationReceived` if the app has been killed. To handle this scenario, you will need to create a service that extends `FirebaseMessagingService`, see [Handling FCM Messages](https://firebase.google.com/docs/cloud-messaging/android/receive).

This plugin does support data-only notifications, but will NOT call `pushNotificationReceived` if the app has been killed. To handle this scenario, you will need to create a service that extends `FirebaseMessagingService`, see [Handling FCM Messages](https://firebase.google.com/docs/cloud-messaging/android/receive).

## Common Issues

On Android, there are various system and app states that can affect the delivery of push notifications:

* If the device has entered [Doze](https://developer.android.com/training/monitoring-device-state/doze-standby) mode, your application may have restricted capabilities. To increase the chance of your notification being received, consider using [FCM high priority messages](https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message).
* There are differences in behavior between development and production. Try testing your app outside of being launched by Android Studio. Read more [here](https://stackoverflow.com/a/50238790/1351469).
- If the device has entered [Doze](https://developer.android.com/training/monitoring-device-state/doze-standby) mode, your application may have restricted capabilities. To increase the chance of your notification being received, consider using [FCM high priority messages](https://firebase.google.com/docs/cloud-messaging/concept-options#setting-the-priority-of-a-message).
- There are differences in behavior between development and production. Try testing your app outside of being launched by Android Studio. Read more [here](https://stackoverflow.com/a/50238790/1351469).

---

Expand All @@ -138,14 +142,24 @@ const addListeners = async () => {
console.error('Registration error: ', err.error);
});

await PushNotifications.addListener('pushNotificationReceived', notification => {
console.log('Push notification received: ', notification);
});

await PushNotifications.addListener('pushNotificationActionPerformed', notification => {
console.log('Push notification action performed', notification.actionId, notification.inputValue);
});
}
await PushNotifications.addListener(
'pushNotificationReceived',
notification => {
console.log('Push notification received: ', notification);
},
);

await PushNotifications.addListener(
'pushNotificationActionPerformed',
notification => {
console.log(
'Push notification action performed',
notification.actionId,
notification.inputValue,
);
},
);
};

const registerNotifications = async () => {
let permStatus = await PushNotifications.checkPermissions();
Expand All @@ -159,12 +173,12 @@ const registerNotifications = async () => {
}

await PushNotifications.register();
}
};

const getDeliveredNotifications = async () => {
const notificationList = await PushNotifications.getDeliveredNotifications();
console.log('delivered notifications', notificationList);
}
};
```

## API
Expand Down
25 changes: 25 additions & 0 deletions src/definitions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,24 @@ export interface PushNotificationsPlugin {
* notification permissions, use `requestPermissions()` first.
*
* @since 1.0.0
* @return {Promise<void>}
*/
register(): Promise<void>;

/**
* Get a list of notifications that are visible on the notifications screen.
*
* @since 1.0.0
* @return {Promise<DeliveredNotifications>}
*/
getDeliveredNotifications(): Promise<DeliveredNotifications>;

/**
* Remove the specified notifications from the notifications screen.
*
* @since 1.0.0
* @param {DeliveredNotifications} delivered
* @return {Promise<void>}
*/
removeDeliveredNotifications(
delivered: DeliveredNotifications,
Expand All @@ -98,6 +102,7 @@ export interface PushNotificationsPlugin {
* Remove all the notifications from the notifications screen.
*
* @since 1.0.0
* @return {Promise<void>}
*/
removeAllDeliveredNotifications(): Promise<void>;

Expand All @@ -107,6 +112,8 @@ export interface PushNotificationsPlugin {
* Only available on Android O or newer (SDK 26+).
*
* @since 1.0.0
* @param {Channel} channel
* @return {Promise<void>}
*/
createChannel(channel: Channel): Promise<void>;

Expand All @@ -116,6 +123,8 @@ export interface PushNotificationsPlugin {
* Only available on Android O or newer (SDK 26+).
*
* @since 1.0.0
* @param { {string} id } args
* @return {Promise<void>}
*/
deleteChannel(args: { id: string }): Promise<void>;

Expand All @@ -125,6 +134,7 @@ export interface PushNotificationsPlugin {
* Only available on Android O or newer (SDK 26+).
*
* @since 1.0.0
* @return {Promise<ListChannelsResult>}
*/
listChannels(): Promise<ListChannelsResult>;

Expand All @@ -136,6 +146,7 @@ export interface PushNotificationsPlugin {
* to display notifications, use local-notifications plugin.
*
* @since 1.0.0
* @return {Promise<PermissionStatus>}
*/
checkPermissions(): Promise<PermissionStatus>;

Expand All @@ -151,6 +162,7 @@ export interface PushNotificationsPlugin {
* the permission without prompting again.
*
* @since 1.0.0
* @return {Promise<PermissionStatus>}
*/
requestPermissions(): Promise<PermissionStatus>;

Expand All @@ -160,6 +172,9 @@ export interface PushNotificationsPlugin {
* Provides the push notification token.
*
* @since 1.0.0
* @param {string} eventName
* @param {({Token} token) => void} listenerFunc
* @return {Promise<PluginListenerHandle>}
*/
addListener(
eventName: 'registration',
Expand All @@ -172,6 +187,9 @@ export interface PushNotificationsPlugin {
* Provides an error with the registration problem.
*
* @since 1.0.0
* @param {string} eventName
* @param {({RegistrationError} error) => void} listenerFunc
* @return {Promise<PluginListenerHandle>}
*/
addListener(
eventName: 'registrationError',
Expand All @@ -182,6 +200,9 @@ export interface PushNotificationsPlugin {
* Called when the device receives a push notification.
*
* @since 1.0.0
* @param {string} eventName
* @param {({PushNotificationSchema} notification) => void} listenerFunc
* @return {Promise<PluginListenerHandle>}
*/
addListener(
eventName: 'pushNotificationReceived',
Expand All @@ -192,6 +213,9 @@ export interface PushNotificationsPlugin {
* Called when an action is performed on a push notification.
*
* @since 1.0.0
* @param {string} eventName
* @param {({ActionPerformed} notification) => void} listenerFunc
* @return {Promise<PluginListenerHandle>}
*/
addListener(
eventName: 'pushNotificationActionPerformed',
Expand All @@ -202,6 +226,7 @@ export interface PushNotificationsPlugin {
* Remove all native listeners for this plugin.
*
* @since 1.0.0
* @return {Promise<void>}
*/
removeAllListeners(): Promise<void>;
}
Expand Down

0 comments on commit 8248d31

Please sign in to comment.