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

Commit e37552d

Browse files
committed
Merge branch 'dev'
* 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 ...
2 parents da34ac1 + faf2440 commit e37552d

30 files changed

+1486
-504
lines changed

CHANGELOG.md

+45
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,55 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77

88
## [Unreleased]
99

10+
### Breaking changes
11+
1012
### Features
1113

1214
### Fixed
1315

16+
17+
## [4.4.0] 2020-07-06
18+
19+
### Breaking changes
20+
21+
- `RNPushNotificationRegistrationService` has been removed, old reference in AndroidManifest must be removed.
22+
- `Notifications.registerNotificationActions()` has been removed and is not required for `actions`.
23+
- `DeviceEventEmitter.addListener('notificationActionReceived', callback)` is replaced by `onAction`.
24+
- Extra receiver must be added to manage actions.
25+
```xml
26+
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
27+
```
28+
- (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.
50+
- (Android/iOS) Add method getScheduledLocalNotifications()[#1466](https://github.com/zo0r/react-native-push-notification/pull/1466)
51+
52+
### Fixed
53+
54+
- (Android) Replace java.util.Random with java.security.SecureRandom [#1497](https://github.com/zo0r/react-native-push-notification/pull/1497)
55+
- (Android) WAKE_LOCK permission removed from documentation. [#1494](https://github.com/zo0r/react-native-push-notification/issues/1494)
56+
- (Android) Some options were ignored on scheduled/repeating notifications (allowWhileIdle, ignoreInForeground).
57+
- (Android/iOS) popInitialInotification might be ignored in `.configure()`
58+
1459
## [3.5.2] - 2020-05-25
1560

1661
### Fixed

README.md

+158-44
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
React Native Local and Remote Notifications for iOS and Android
77

8+
9+
## 🎉 Version 4.0.0 is live ! 🎉
10+
11+
Check out for changes in the CHANGELOG:
12+
13+
[Changelog](https://github.com/zo0r/react-native-push-notification/blob/master/CHANGELOG.md)
14+
15+
816
## Supported React Native Versions
917

1018
| Component Version | RN Versions | README |
@@ -29,6 +37,8 @@ Changelog is available from version 3.1.3 here: [Changelog](https://github.com/z
2937

3038
`yarn add react-native-push-notification`
3139

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+
3242
**NOTE: For Android, you will still have to manually update the AndroidManifest.xml (as below) in order to use Scheduled Notifications.**
3343

3444
## Issues
@@ -70,8 +80,6 @@ In your `android/app/src/main/AndroidManifest.xml`
7080

7181
```xml
7282
.....
73-
<uses-permission android:name="android.permission.WAKE_LOCK" />
74-
7583
<uses-permission android:name="android.permission.VIBRATE" />
7684
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
7785

@@ -84,10 +92,14 @@ In your `android/app/src/main/AndroidManifest.xml`
8492
<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
8593
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
8694
android:value="false"/>
95+
<!-- Change the value to false if you don't want the creation of the default channel -->
96+
<meta-data android:name="com.dieam.reactnativepushnotification.channel_create_default"
97+
android:value="true"/>
8798
<!-- Change the resource name to your App's accent color - or any other color you want -->
8899
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
89100
android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->
90101

102+
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
91103
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationPublisher" />
92104
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
93105
<intent-filter>
@@ -222,6 +234,19 @@ PushNotification.configure({
222234
notification.finish(PushNotificationIOS.FetchResult.NoData);
223235
},
224236

237+
// (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+
225250
// IOS ONLY (optional): default: all - Permissions to register.
226251
permissions: {
227252
alert: true,
@@ -276,22 +301,31 @@ PushNotification.localNotification({
276301
/* Android Only Properties */
277302
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
278303
ticker: "My Notification Ticker", // (optional)
304+
showWhen: true, // (optional) default: true
279305
autoCancel: true, // (optional) default: true
280306
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
307+
largeIconUrl: "https://www.example.tld/picture.jpg", // (optional) default: undefined
281308
smallIcon: "ic_notification", // (optional) default: "ic_notification" with fallback for "ic_launcher"
282309
bigText: "My big text that will be shown when notification is expanded", // (optional) default: "message" prop
283310
subText: "This is a subText", // (optional) default: none
311+
bigPictureUrl: "https://www.example.tld/picture.jpg", // (optional) default: undefined
284312
color: "red", // (optional) default: system default
285313
vibrate: true, // (optional) default: true
286314
vibration: 300, // vibration length in milliseconds, ignored if vibrate=false, default: 1000
287315
tag: "some_tag", // (optional) add tag to message
288316
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
289318
ongoing: false, // (optional) set whether this is an "ongoing" notification
290319
priority: "high", // (optional) set notification priority, default: high
291320
visibility: "private", // (optional) set notification visibility, default: private
292321
importance: "high", // (optional) set notification importance, default: high
293322
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
294323
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
295329

296330
/* iOS only properties */
297331
alertAction: "view", // (optional) default: view
@@ -305,7 +339,6 @@ PushNotification.localNotification({
305339
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)
306340
number: 10, // (optional) Valid 32 bit integer specified as string. default: none (Cannot be zero)
307341
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
309342
});
310343
```
311344

@@ -333,38 +366,115 @@ In the location notification json specify the full file name:
333366

334367
soundName: 'my_sound.mp3'
335368

336-
## Cancelling notifications
369+
## Channel Management (Android)
337370

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`.
339372

340-
#### Android
373+
The pattern of `channel_id` is:
341374

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+
```
343378

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).
382+
383+
you can avoid the default creation by using this:
384+
385+
```xml
386+
<meta-data android:name="com.dieam.reactnativepushnotification.channel_create_default"
387+
android:value="false"/>
388+
```
389+
390+
**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.
396+
397+
```xml
398+
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name.[CHANNEL_ID]"
399+
android:value="YOUR NOTIFICATION CHANNEL NAME FOR CHANNEL_ID"/>
400+
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description.[CHANNEL_ID]"
401+
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION FOR CHANNEL_ID"/>
402+
```
403+
404+
For example:
405+
406+
```xml
407+
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name.rn-push-notification-channel-id-4-300"
408+
android:value="YOUR NOTIFICATION CHANNEL NAME FOR SILENT CHANNEL"/>
409+
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description.rn-push-notification-channel-id-4-300"
410+
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION FOR SILENT CHANNEL"/>
411+
```
412+
413+
If you want to use a different default channel for remote notification, refer to the documentation of Firebase:
414+
415+
[Set up a Firebase Cloud Messaging client app on Android](https://firebase.google.com/docs/cloud-messaging/android/client?hl=fr)
416+
417+
```xml
418+
<meta-data
419+
android:name="com.google.firebase.messaging.default_notification_channel_id"
420+
android:value="@string/default_notification_channel_id" />
421+
```
422+
423+
### List channels
424+
425+
You can list available channels with:
426+
427+
```js
428+
PushNotification.getChannels(function (channel_ids) {
429+
console.log(channel_ids); // ['channel_id_1']
430+
});
431+
```
432+
433+
### Channel exists
434+
435+
You can check if a channel exists with:
436+
437+
```js
438+
PushNotification.channelExists(channel_id, function (exists) {
439+
console.log(exists); // true/false
440+
});
441+
```
442+
443+
### Channel blocked
444+
445+
You can check if a channel blocked with:
446+
447+
```js
448+
PushNotification.channelBlocked(channel_id, function (blocked) {
449+
console.log(blocked); // true/false
350450
});
351-
PushNotification.cancelLocalNotifications({id: '123'});
352451
```
353452

354-
#### IOS
453+
### List channels
454+
455+
You can list available channels with:
355456

356-
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.
357466

358467
```javascript
359-
// IOS
360468
PushNotification.localNotification({
361469
...
362-
userInfo: { id: '123' }
470+
id: '123'
363471
...
364472
});
365473
PushNotification.cancelLocalNotifications({id: '123'});
366474
```
367475

476+
**iOS: `userInfo` is populated `id` if not defined this allow the previous method**
477+
368478
### 2) cancelAllLocalNotifications
369479

370480
`PushNotification.cancelAllLocalNotifications()`
@@ -418,6 +528,31 @@ Removes the specified notifications from Notification Center
418528
| ----------- | ----- | -------- | ---------------------------------- |
419529
| identifiers | array | Yes | Array of notification identifiers. |
420530

531+
### 6) getScheduledLocalNotifications
532+
533+
```javascript
534+
PushNotificationIOS.getScheduledLocalNotifications(callback);
535+
```
536+
537+
Provides you with a list of the app’s scheduled local notifications that are yet to be displayed
538+
539+
**Parameters:**
540+
541+
| Name | Type | Required | Description |
542+
| -------- | -------- | -------- | ----------------------------------------------------------- |
543+
| callback | function | Yes | Function which receive an array of delivered notifications. |
544+
545+
Returns an array of local scheduled notification objects containing:
546+
547+
| Name | Type | Description |
548+
| -------------- | ------ | ----------------------------------------- |
549+
| 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. |
421556

422557
## Abandon Permissions
423558

@@ -486,37 +621,16 @@ Property `repeatType` could be one of `month`, `week`, `day`, `hour`, `minute`,
486621

487622
(Android only) [Refer](https://github.com/zo0r/react-native-push-notification/issues/151) to this issue to see an example of a notification action.
488623

489-
Two things are required to setup notification actions.
490-
491-
### 1) Specify notification actions for a notification
492-
493624
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.
494625

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']`
498627

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)`.
500629

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`:
502631

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
508-
PushNotificationAndroid.registerNotificationActions(['Accept','Reject','Yes','No']);
509-
DeviceEventEmitter.addListener('notificationActionReceived', function(action){
510-
console.log ('Notification action received: ' + action);
511-
const info = JSON.parse(action.dataJSON);
512-
if (info.action == 'Accept') {
513-
// Do work pertaining to Accept action here
514-
} else if (info.action == 'Reject') {
515-
// Do work pertaining to Reject action here
516-
}
517-
// Add all the required actions handlers
518-
});
519-
})();
632+
```xml
633+
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationActions" />
520634
```
521635

522636
For iOS, you can use this [package](https://github.com/holmesal/react-native-ios-notification-actions) to add notification actions.

android/.classpath

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8/"/>
4+
<classpathentry kind="con" path="org.eclipse.buildship.core.gradleclasspathcontainer"/>
5+
<classpathentry kind="output" path="bin/default"/>
6+
</classpath>

android/.project

+6
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
<projects>
66
</projects>
77
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
813
<buildCommand>
914
<name>org.eclipse.buildship.core.gradleprojectbuilder</name>
1015
<arguments>
1116
</arguments>
1217
</buildCommand>
1318
</buildSpec>
1419
<natures>
20+
<nature>org.eclipse.jdt.core.javanature</nature>
1521
<nature>org.eclipse.buildship.core.gradleprojectnature</nature>
1622
</natures>
1723
</projectDescription>

0 commit comments

Comments
 (0)