Skip to content

Commit

Permalink
docs: unsubscribe even listeners on unmount (#340)
Browse files Browse the repository at this point in the history
  • Loading branch information
vonovak authored Oct 21, 2021
1 parent b85827c commit 0ff2161
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,11 @@ export const App = () => {
const [permissions, setPermissions] = useState({});

useEffect(() => {
PushNotificationIOS.addEventListener('notification', onRemoteNotification);
const type = 'notification';
PushNotificationIOS.addEventListener(type, onRemoteNotification);
return () => {
PushNotificationIOS.removeEventListener(type);
};
});

const onRemoteNotification = (notification) => {
Expand Down Expand Up @@ -216,7 +220,11 @@ export const App = () => {
};

useEffect(() => {
PushNotificationIOS.addEventListener('notification', onRemoteNotification);
const type = 'notification';
PushNotificationIOS.addEventListener(type, onRemoteNotification);
return () => {
PushNotificationIOS.removeEventListener(type);
};
});

const onRemoteNotification = (notification) => {
Expand All @@ -234,9 +242,10 @@ export const App = () => {
};
};
```

## How to recieve rich notification in remote

Follow these [article](https://firebase.google.com/docs/cloud-messaging/ios/send-image) to create rich notification for your own
Follow this [article](https://firebase.google.com/docs/cloud-messaging/ios/send-image) to create rich notification of your own

# Reference

Expand Down Expand Up @@ -295,7 +304,7 @@ details is an object containing:
- `isSilent` : If true, the notification will appear without sound (optional).
- `category` : The category of this notification, required for actionable notifications (optional).
- `userInfo` : An object containing additional notification data (optional).
- `image` : It's useful if you need to diplay rich notification (optional).
- `image` : It's useful if you need to diplay rich notification (optional).
- `applicationIconBadgeNumber` The number to display as the app's icon badge. Setting the number to 0 removes the icon badge (optional).
- `repeatInterval` : The interval to repeat as a string. Possible values: `minute`, `hour`, `day`, `week`, `month`, `year` (optional).

Expand Down Expand Up @@ -412,8 +421,8 @@ Removes the specified pending notifications from Notification Center

**Parameters:**

| Name | Type | Required | Description |
| ----------- | ----- | -------- | ---------------------------------- |
| Name | Type | Required | Description |
| ----------- | -------- | -------- | ---------------------------------- |
| identifiers | string[] | Yes | Array of notification identifiers. |

---
Expand Down Expand Up @@ -473,8 +482,8 @@ Removes the specified delivered notifications from Notification Center

**Parameters:**

| Name | Type | Required | Description |
| ----------- | ----- | -------- | ---------------------------------- |
| Name | Type | Required | Description |
| ----------- | -------- | -------- | ---------------------------------- |
| identifiers | string[] | Yes | Array of notification identifiers. |

---
Expand Down

0 comments on commit 0ff2161

Please sign in to comment.