Skip to content
This repository was archived by the owner on Jan 14, 2025. It is now read-only.

Commit 676aa03

Browse files
committed
Fix order in README.md and formatting.
1 parent 502efe0 commit 676aa03

File tree

1 file changed

+59
-54
lines changed

1 file changed

+59
-54
lines changed

README.md

Lines changed: 59 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ Changelog is available from version 3.1.3 here: [Changelog](https://github.com/z
2222
## Installation
2323

2424
### NPM
25+
2526
`npm install --save react-native-push-notification`
2627

2728
### Yarn
29+
2830
`yarn add react-native-push-notification`
2931

3032
**NOTE: For Android, you will still have to manually update the AndroidManifest.xml (as below) in order to use Scheduled Notifications.**
@@ -56,6 +58,7 @@ In your `android/build.gradle`
5658
...
5759
}
5860
```
61+
5962
In your `android/build.gradle`
6063

6164
```gradle
@@ -74,6 +77,7 @@ ext {
7477
**NOTE: localNotification() works without changes in the application part, while localNotificationSchedule() only works with these changes:**
7578

7679
In your `android/app/src/main/AndroidManifest.xml`
80+
7781
```xml
7882
.....
7983
<!-- < Only if you're using GCM or localNotificationSchedule() > -->
@@ -140,6 +144,7 @@ In your `android/app/src/main/AndroidManifest.xml`
140144

141145
If not using a built in Android color (`@android:color/{name}`) for the `notification_color` `meta-data` item.
142146
In `android/app/src/main/res/values/colors.xml` (Create the file if it doesn't exist).
147+
143148
```xml
144149
<resources>
145150
<color name="white">#FFF</color>
@@ -188,12 +193,12 @@ var PushNotification = require("react-native-push-notification");
188193

189194
PushNotification.configure({
190195
// (optional) Called when Token is generated (iOS and Android)
191-
onRegister: function(token) {
196+
onRegister: function (token) {
192197
console.log("TOKEN:", token);
193198
},
194199

195200
// (required) Called when a remote or local notification is opened or received
196-
onNotification: function(notification) {
201+
onNotification: function (notification) {
197202
console.log("NOTIFICATION:", notification);
198203

199204
// process the notification
@@ -209,7 +214,7 @@ PushNotification.configure({
209214
permissions: {
210215
alert: true,
211216
badge: true,
212-
sound: true
217+
sound: true,
213218
},
214219

215220
// Should the initial notification be popped automatically
@@ -221,7 +226,7 @@ PushNotification.configure({
221226
* - Specified if permissions (ios) and token (android and ios) will requested or not,
222227
* - if not, you must call PushNotificationsHandler.requestPermissions() later
223228
*/
224-
requestPermissions: true
229+
requestPermissions: true,
225230
});
226231
```
227232

@@ -255,39 +260,39 @@ EXAMPLE:
255260

256261
```javascript
257262
PushNotification.localNotification({
258-
/* Android Only Properties */
259-
id: '0', // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
260-
ticker: "My Notification Ticker", // (optional)
261-
autoCancel: true, // (optional) default: true
262-
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
263-
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
264-
bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
265-
subText: "This is a subText", // (optional) default: none
266-
color: "red", // (optional) default: system default
267-
vibrate: true, // (optional) default: true
268-
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
269-
tag: 'some_tag', // (optional) add tag to message
270-
group: "group", // (optional) add group to message
271-
ongoing: false, // (optional) set whether this is an "ongoing" notification
272-
priority: "high", // (optional) set notification priority, default: high
273-
visibility: "private", // (optional) set notification visibility, default: private
274-
importance: "high", // (optional) set notification importance, default: high
275-
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
276-
ignoreInForeground: false, // (optional) if true, the notification will not be visible when the app is in the foreground (useful for parity with how iOS notifications appear)
277-
278-
/* iOS only properties */
279-
alertAction: 'view', // (optional) default: view
280-
category: '', // (optional) default: empty string
281-
userInfo: {}, // (optional) default: {} (using null throws a JSON value '<null>' error)
282-
283-
/* iOS and Android properties */
284-
title: "My Notification Title", // (optional)
285-
message: "My Notification Message", // (required)
286-
playSound: false, // (optional) default: true
287-
soundName: 'default', // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
288-
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
289-
repeatType: 'day', // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
290-
actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
263+
/* Android Only Properties */
264+
id: "0", // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
265+
ticker: "My Notification Ticker", // (optional)
266+
autoCancel: true, // (optional) default: true
267+
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
268+
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
269+
bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
270+
subText: "This is a subText", // (optional) default: none
271+
color: "red", // (optional) default: system default
272+
vibrate: true, // (optional) default: true
273+
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
274+
tag: "some_tag", // (optional) add tag to message
275+
group: "group", // (optional) add group to message
276+
ongoing: false, // (optional) set whether this is an "ongoing" notification
277+
priority: "high", // (optional) set notification priority, default: high
278+
visibility: "private", // (optional) set notification visibility, default: private
279+
importance: "high", // (optional) set notification importance, default: high
280+
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
281+
ignoreInForeground: false, // (optional) if true, the notification will not be visible when the app is in the foreground (useful for parity with how iOS notifications appear)
282+
283+
/* iOS only properties */
284+
alertAction: "view", // (optional) default: view
285+
category: "", // (optional) default: empty string
286+
userInfo: {}, // (optional) default: {} (using null throws a JSON value '<null>' error)
287+
288+
/* iOS and Android properties */
289+
title: "My Notification Title", // (optional)
290+
message: "My Notification Message", // (required)
291+
playSound: false, // (optional) default: true
292+
soundName: "default", // (optional) Sound to play when the notification is shown. Value of 'default' plays the default sound. It can be set to a custom sound such as 'android.resource://com.xyz/raw/my_sound'. It will look for the 'my_sound' audio file in 'res/raw' directory and play it. default: 'default' (default sound is played)
293+
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
294+
repeatType: "day", // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
295+
actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
291296
});
292297
```
293298

@@ -301,7 +306,7 @@ EXAMPLE:
301306
PushNotification.localNotificationSchedule({
302307
//... You can use all the options from localNotifications
303308
message: "My Notification Message", // (required)
304-
date: new Date(Date.now() + 60 * 1000) // in 60 secs
309+
date: new Date(Date.now() + 60 * 1000), // in 60 secs
305310
});
306311
```
307312

@@ -333,6 +338,20 @@ PushNotification.localNotification({
333338
PushNotification.cancelLocalNotifications({id: '123'});
334339
```
335340

341+
#### IOS
342+
343+
The `userInfo` parameter for `PushNotification.localNotification` is required for this operation and must contain an `id` parameter. The id supplied will then be used for the cancel operation.
344+
345+
```javascript
346+
// IOS
347+
PushNotification.localNotification({
348+
...
349+
userInfo: { id: '123' }
350+
...
351+
});
352+
PushNotification.cancelLocalNotifications({id: '123'});
353+
```
354+
336355
## Notification priority
337356

338357
(optional) Specify `priority` to set priority of notification. Default value: "high"
@@ -375,31 +394,17 @@ Available options:
375394

376395
More information: https://developer.android.com/reference/android/app/NotificationManager#IMPORTANCE_DEFAULT
377396

378-
## Notification while idle ##
397+
## Notification while idle
379398

380399
(optional) Specify `allowWhileIdle` to set if the notification should be allowed to execute even when the system is on low-power idle modes.
381400

382-
On Android 6.0 (API level 23) and forward, the Doze was introduced to reduce battery consumption when the device is unused for long periods of time. But while on Doze the AlarmManager alarms (used to show scheduled notifications) are deferred to the next maintenance window. This may cause the notification to be delayed while on Doze.
401+
On Android 6.0 (API level 23) and forward, the Doze was introduced to reduce battery consumption when the device is unused for long periods of time. But while on Doze the AlarmManager alarms (used to show scheduled notifications) are deferred to the next maintenance window. This may cause the notification to be delayed while on Doze.
383402

384403
This can significantly impact the power use of the device when idle. So it must only be used when the notification is required to go off on a exact time, for example on a calendar notification.
385404

386405
More information:
387406
https://developer.android.com/training/monitoring-device-state/doze-standby
388407

389-
#### IOS
390-
391-
The `userInfo` parameter for `PushNotification.localNotification` is required for this operation and must contain an `id` parameter. The id supplied will then be used for the cancel operation.
392-
393-
```javascript
394-
// IOS
395-
PushNotification.localNotification({
396-
...
397-
userInfo: { id: '123' }
398-
...
399-
});
400-
PushNotification.cancelLocalNotifications({id: '123'});
401-
```
402-
403408
### 2) cancelAllLocalNotifications
404409

405410
`PushNotification.cancelAllLocalNotifications()`

0 commit comments

Comments
 (0)