You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Jan 14, 2025. It is now read-only.
* dev: (48 commits)
Release v4.0.0.
Use SecureRandom and remove `onNotification` call for Scheduled notifications when there is no user interation.
Update CHANGELOG.md
replaced java.util.Random with java.security.SecureRandom in RNPushNotification.java
Remove WAKE_LOCK from documentation. #1494
Add `onRegistrationError`.
Allow override the channel name and description in App. Add the detection of blocked channels.
Fix notif reference undefined.
Fix typo.
Add notification id to iOS if userInfo doesn't exist
`userInfo` is now populated with id by default to allow operation based on `id`
"@react-native-community/push-notification-ios": "^1.2.2"
add docs
add example button to log scheduled notifications
bump @react-native-community/push-notification-ios to v1.2.1
format date for scheduled notifications object
map scheduled local notifications to united return object for both platforms
add missing getters for notification attributes
change naming of notification params returned on android, return date in unix timestamp as before
format android getScheduledLocalNotifications return object to match iOS return object
...
- (iOS) `userInfo` is now populated with id by default to allow operation based on `id`.
29
+
30
+
### Features
31
+
32
+
- (Android) `actions` accept an array of strings.
33
+
- (Android) `invokeApp` allow you to handle actions in background without invoking the application.
34
+
- (Android) `onAction` has been added to `.configure()` to handle action in background.
35
+
- (Android) `PushNotification.invokeApp(notification)` allow you to invoke the application when in background (notification for initial notification).
36
+
- (Android) `PushNotification.getChannels(callback)` allow you to get the list of channels.
37
+
- (Android) `PushNotification.channelExists(channel_id, callback)` allow you to check of a channel exists.
38
+
- (Android) `PushNotification.channelBlocked(channel_id, callback)` allow you to check of a channel is blocked. Based on [#1249](https://github.com/zo0r/react-native-push-notification/pull/1249)
39
+
- (Android) `PushNotification.deleteChannel(channel_id)` allow you to delete a channel.
40
+
- (Android) Add `largeIconUrl` to load a largeIcon based on Url. Based on [#1444](https://github.com/zo0r/react-native-push-notification/pull/1444)
41
+
- (Android) Add `bigPictureUrl` to load a picture based on Url. Based on [#1444](https://github.com/zo0r/react-native-push-notification/pull/1444)
42
+
- (Android) Add `shortcutId` for better badges management.
43
+
- (Android) Add `showWhen` to display "when" it was published, default: true.
44
+
- (Android) Add `groupSummary` to allow grouping notifications. Based on [#1253](https://github.com/zo0r/react-native-push-notification/pull/1253)
45
+
- (Android) Add `channelId`, custom channel_id in android. Based on [#1159](https://github.com/zo0r/react-native-push-notification/pull/1159)
46
+
- (Android) Add `channelName`, custom channel_name in android.
47
+
- (Android) Add `channelDescription`, custom channel_description in android.
48
+
- (iOS) Add fire date in notification response, NOTE: `push-notification-ios` in version `> 1.2.0`[#1345](https://github.com/zo0r/react-native-push-notification/pull/1345)
49
+
- (iOS) `onRegistrationError` has been added to `.configure()` to handle `registrationError` events.
@@ -29,6 +37,8 @@ Changelog is available from version 3.1.3 here: [Changelog](https://github.com/z
29
37
30
38
`yarn add react-native-push-notification`
31
39
40
+
**NOTE: If you target iOS you also need to follow the [installation instructions for PushNotificationIOS](https://github.com/react-native-community/react-native-push-notification-ios) since this package depends on it.**
41
+
32
42
**NOTE: For Android, you will still have to manually update the AndroidManifest.xml (as below) in order to use Scheduled Notifications.**
33
43
34
44
## Issues
@@ -70,8 +80,6 @@ In your `android/app/src/main/AndroidManifest.xml`
// (optional) Called when Registered Action is pressed and invokeApp is false, if true onNotification will be called (Android)
238
+
onAction:function (notification) {
239
+
console.log("ACTION:", notification.action);
240
+
console.log("NOTIFICATION:", notification);
241
+
242
+
// process the action
243
+
},
244
+
245
+
// (optional) Called when the user fails to register for remote notifications. Typically occurs when APNS is having issues, or the device is a simulator. (iOS)
246
+
onRegistrationError:function(err) {
247
+
console.error(err.message, err);
248
+
}
249
+
225
250
// IOS ONLY (optional): default: all - Permissions to register.
color:"red", // (optional) default: system default
285
313
vibrate:true, // (optional) default: true
286
314
vibration:300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
287
315
tag:"some_tag", // (optional) add tag to message
288
316
group:"group", // (optional) add group to message
317
+
groupSummary:false, // (optional) set this notification to be the group summary for a group of notifications, default: false
289
318
ongoing:false, // (optional) set whether this is an "ongoing" notification
290
319
priority:"high", // (optional) set notification priority, default: high
291
320
visibility:"private", // (optional) set notification visibility, default: private
292
321
importance:"high", // (optional) set notification importance, default: high
293
322
allowWhileIdle:false, // (optional) set notification to work while on doze, default: false
294
323
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)
324
+
shortcutId:"shortcut-id", // (optional) If this notification is duplicative of a Launcher shortcut, sets the id of the shortcut, in case the Launcher wants to hide the shortcut, default undefined
325
+
channelId:"your-custom-channel-id", // (optional) custom channelId, if the channel doesn't exist, it will be created with options passed above (importance, vibration, sound). Once the channel is created, the channel will not be update. Make sure your channelId is different if you change these options. If you have created a custom channel, it will apply options of the channel.
326
+
327
+
actions:'["Yes", "No"]', // (Android only) See the doc for notification actions to know more
328
+
invokeApp:true, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true
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)
306
340
number:10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
307
341
repeatType:"day", // (optional) Repeating interval. Check 'Repeating Notifications' section for more info.
308
-
actions:'["Yes", "No"]', // (Android only) See the doc for notification actions to know more
309
342
});
310
343
```
311
344
@@ -333,38 +366,115 @@ In the location notification json specify the full file name:
333
366
334
367
soundName: 'my_sound.mp3'
335
368
336
-
## Cancelling notifications
369
+
## Channel Management (Android)
337
370
338
-
### 1) cancelLocalNotifications
371
+
This library doesn't include a full Channel Management at the moment. Channels are generated on the fly when you pass options to `PushNotification.localNotification` or `PushNotification.localNotificationSchedule`.
339
372
340
-
#### Android
373
+
The pattern of `channel_id` is:
341
374
342
-
The `id` parameter for `PushNotification.localNotification` is required for this operation. The id supplied will then be used for the cancel operation.
375
+
```
376
+
rn-push-notification-channel-id-(importance: default "4")(-soundname, default if playSound "-default")-(vibration, default "300")
377
+
```
343
378
344
-
```javascript
345
-
// Android
346
-
PushNotification.localNotification({
347
-
...
348
-
id:'123'
349
-
...
379
+
By default, 1 channel is created:
380
+
381
+
- rn-push-notification-channel-id-4-default-300 (used for remote notification if none already exist).
**NOTE: Without channel, remote notifications don't work**
391
+
392
+
In the notifications options, you can provide a custom channel id with `channelId: "your-custom-channel-id"`, if the channel doesn't exist, it will be created with options passed above (importance, vibration, sound). Once the channel is created, the channel will not be update. Make sure your `channelId` is different if you change these options. If you have created a custom channel in another way, it will apply options of the channel.
393
+
394
+
Custom and generated channels can have custom name and description in the `AndroidManifest.xml`, only if the library is responsible of the creation of the channel.
395
+
You can also use `channelName` and `channelDescription` when you use to override the name or description. Once the channel is created, you won't be able to update them.
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.
457
+
```js
458
+
PushNotification.deleteChannel(channel_id);
459
+
```
460
+
461
+
## Cancelling notifications
462
+
463
+
### 1) cancelLocalNotifications
464
+
465
+
The `id` parameter for `PushNotification.localNotification` is required for this operation. The id supplied will then be used for the cancel operation.
| id | number | The identifier of this notification. |
550
+
| date | Date | The fire date of this notification. |
551
+
| title | string | The title of this notification. |
552
+
| message | string | The message body of this notification. |
553
+
| soundName | string | The sound name of this notification. |
554
+
| repeatInterval | number | The repeat interval of this notification. |
555
+
| number | number | App notification badge count number. |
421
556
422
557
## Abandon Permissions
423
558
@@ -486,37 +621,16 @@ Property `repeatType` could be one of `month`, `week`, `day`, `hour`, `minute`,
486
621
487
622
(Android only) [Refer](https://github.com/zo0r/react-native-push-notification/issues/151) to this issue to see an example of a notification action.
488
623
489
-
Two things are required to setup notification actions.
490
-
491
-
### 1) Specify notification actions for a notification
492
-
493
624
This is done by specifying an `actions` parameters while configuring the local notification. This is an array of strings where each string is a notification action that will be presented with the notification.
494
625
495
-
For e.g. `actions: '["Accept", "Reject"]' // Must be in string format`
496
-
497
-
The array itself is specified in string format to circumvent some problems because of the way JSON arrays are handled by react-native android bridge.
626
+
For e.g. `actions: ['Accept', 'Reject']`
498
627
499
-
### 2) Specify handlers for the notification actions
628
+
When you handle actions in background (`invokeApp: false`), you can open the application and pass the initial notification by using use `PushNotification.invokeApp(notification)`.
500
629
501
-
For each action specified in the `actions` field, we need to add a handler that is called when the user clicks on the action. This can be done in the `componentWillMount` of your main app file or in a separate file which is imported in your main app file. Notification actions handlers can be configured as below:
630
+
Make sure you have the receiver in `AndroidManifest.xml`:
502
631
503
-
```
504
-
import PushNotificationAndroid from 'react-native-push-notification'
505
-
506
-
(function() {
507
-
// Register all the valid actions for notifications here and add the action handler for each action
0 commit comments