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

Commit b69f67b

Browse files
committed
Prepare next release
1 parent bedc8f6 commit b69f67b

File tree

13 files changed

+195
-277
lines changed

13 files changed

+195
-277
lines changed

CHANGELOG.md

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,37 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
88

99
### Breaking changes
1010

11+
- (Android) Channel Management: In order to limit the scope of responsability of this library, developers are now responsible of the creation of the channels. You can find the documentation at https://github.com/zo0r/react-native-push-notification#channel-management-android. These changes are also made to allow improvements in the future of the library. Here the list of impacts:
12+
- You must create your channels before triggering a notification.
13+
- These entries in `AndroidManifest` are deprecated:
14+
```xml
15+
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name" android:value="..."/>
16+
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description" android:value="..."/>
17+
<meta-data android:name="com.dieam.reactnativepushnotification.channel_create_default" android:value="..."/>
18+
```
19+
- Followings options changed on Android in `localNotification` and `localNotificationSchedule`:
20+
- `channelId` becomes mandatory (warning if not provided)
21+
- `channelName` is deprecated
22+
- `channelDescription` is deprecated
23+
- `importance` is deprecated
24+
- These changes help to avoid an issue [#1649](https://github.com/zo0r/react-native-push-notification/issues/1649)
25+
- (Android) Remove check for the intent `BOOT_COMPLETED`, this should allow more intent action such as `QUICKBOOT_POWERON`. It's recommended to update `AndroidManifest`, the `RNPushNotificationBootEventReceiver` to:
26+
```xml
27+
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
28+
<intent-filter>
29+
<action android:name="android.intent.action.BOOT_COMPLETED" />
30+
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
31+
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
32+
</intent-filter>
33+
</receiver>
34+
```
1135
- `@react-native-community/push-notification-ios` is now a `peerDependency`, please make sure that you installed this library with NPM or YARN.
1236
- (Android) Fix a bug where notification data are not inside `data` property after been pressed by user. When sending notification + data and app in background.
13-
14-
### Features
37+
- (Android) Add more fields from the firebase notification part. (Thanks to @fattomhk with this PR [#1626](https://github.com/zo0r/react-native-push-notification/pull/1626))
38+
- `notificationPriority`
39+
- `image`
40+
- `tag`
41+
- `visibility`
1542

1643
### Fixed
1744

README.md

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -89,17 +89,9 @@ In your `android/app/src/main/AndroidManifest.xml`
8989
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
9090

9191
<application ....>
92-
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name"
93-
android:value="YOUR NOTIFICATION CHANNEL NAME"/>
94-
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
95-
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>
96-
9792
<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
9893
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
9994
android:value="false"/>
100-
<!-- Change the value to false if you don't want the creation of the default channel -->
101-
<meta-data android:name="com.dieam.reactnativepushnotification.channel_create_default"
102-
android:value="true"/>
10395
<!-- Change the resource name to your App's accent color - or any other color you want -->
10496
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
10597
android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->
@@ -109,6 +101,8 @@ In your `android/app/src/main/AndroidManifest.xml`
109101
<receiver android:name="com.dieam.reactnativepushnotification.modules.RNPushNotificationBootEventReceiver">
110102
<intent-filter>
111103
<action android:name="android.intent.action.BOOT_COMPLETED" />
104+
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
105+
<action android:name="com.htc.intent.action.QUICKBOOT_POWERON"/>
112106
</intent-filter>
113107
</receiver>
114108

@@ -307,6 +301,7 @@ EXAMPLE:
307301
```javascript
308302
PushNotification.localNotification({
309303
/* Android Only Properties */
304+
channelId: "your-channel-id", // (required) 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.
310305
ticker: "My Notification Ticker", // (optional)
311306
showWhen: true, // (optional) default: true
312307
autoCancel: true, // (optional) default: true
@@ -325,10 +320,8 @@ PushNotification.localNotification({
325320
ongoing: false, // (optional) set whether this is an "ongoing" notification
326321
priority: "high", // (optional) set notification priority, default: high
327322
visibility: "private", // (optional) set notification visibility, default: private
328-
importance: "high", // (optional) set notification importance, default: high
329323
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)
330324
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
331-
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.
332325
onlyAlertOnce: false, // (optional) alert will open only once with sound and notify, default: false
333326

334327
when: null, // (optionnal) Add a timestamp pertaining to the notification (usually the time the event occurred). For apps targeting Build.VERSION_CODES.N and above, this time is not shown anymore by default and must be opted into by using `showWhen`, default: null.
@@ -337,7 +330,7 @@ PushNotification.localNotification({
337330

338331
messageId: "google:message_id", // (optional) added as `message_id` to intent extras so opening push notification can find data stored by @react-native-firebase/messaging module.
339332

340-
actions: '["Yes", "No"]', // (Android only) See the doc for notification actions to know more
333+
actions: ["Yes", "No"], // (Android only) See the doc for notification actions to know more
341334
invokeApp: true, // (optional) This enable click on actions to bring back the application to foreground or stay in background, default: true
342335

343336
/* iOS only properties */
@@ -395,14 +388,14 @@ In the location notification json specify the full file name:
395388

396389
## Channel Management (Android)
397390

398-
To use custom channels, create them at startup and pass the matching `channelId` through to `PushNotification.localNotification`
391+
To use channels, create them at startup and pass the matching `channelId` through to `PushNotification.localNotification` or `PushNotification.localNotificationSchedule`.
399392

400393
```javascript
401394
PushNotification.createChannel(
402395
{
403-
channelId: "custom-channel-id", // (required)
404-
channelName: "Custom channel", // (required)
405-
channelDescription: "A custom channel to categorise your custom notifications", // (optional) default: undefined.
396+
channelId: "channel-id", // (required)
397+
channelName: "My channel", // (required)
398+
channelDescription: "A channel to categorise your notifications", // (optional) default: undefined.
406399
soundName: "default", // (optional) See `soundName` parameter of `localNotification` function
407400
importance: 4, // (optional) default: 4. Int value of the Android notification importance
408401
vibrate: true, // (optional) default: true. Creates the default vibration patten if true.
@@ -411,47 +404,9 @@ To use custom channels, create them at startup and pass the matching `channelId`
411404
);
412405
```
413406

414-
Channels with ids that do not exist are generated on the fly when you pass options to `PushNotification.localNotification` or `PushNotification.localNotificationSchedule`.
415-
416-
The pattern of `channel_id` is:
417-
418-
```
419-
rn-push-notification-channel-id-(importance: default "4")(-soundname, default if playSound "-default")-(vibration, default "300")
420-
```
421-
422-
By default, 1 channel is created:
423-
424-
- rn-push-notification-channel-id-4-default-300 (used for remote notification if none already exist).
425-
426-
you can avoid the default creation by using this:
427-
428-
```xml
429-
<meta-data android:name="com.dieam.reactnativepushnotification.channel_create_default"
430-
android:value="false"/>
431-
```
432-
433407
**NOTE: Without channel, remote notifications don't work**
434408

435-
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.
436-
437-
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.
438-
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.
439-
440-
```xml
441-
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name.[CHANNEL_ID]"
442-
android:value="YOUR NOTIFICATION CHANNEL NAME FOR CHANNEL_ID"/>
443-
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description.[CHANNEL_ID]"
444-
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION FOR CHANNEL_ID"/>
445-
```
446-
447-
For example:
448-
449-
```xml
450-
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_name.rn-push-notification-channel-id-4-300"
451-
android:value="YOUR NOTIFICATION CHANNEL NAME FOR SILENT CHANNEL"/>
452-
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description.rn-push-notification-channel-id-4-300"
453-
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION FOR SILENT CHANNEL"/>
454-
```
409+
In the notifications options, you must provide a channel id with `channelId: "your-channel-id"`, if the channel doesn't exist the notification might not e triggered. Once the channel is created, the channel cannot be update. Make sure your `channelId` is different if you change these options. If you have created a channel in another way, it will apply options of the channel.
455410

456411
If you want to use a different default channel for remote notification, refer to the documentation of Firebase:
457412

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,8 @@ public RNPushNotification(ReactApplicationContext reactContext) {
5757
mRNPushNotificationHelper = new RNPushNotificationHelper(applicationContext);
5858
// This is used to delivery callbacks to JS
5959
mJsDelivery = new RNPushNotificationJsDelivery(reactContext);
60-
61-
mRNPushNotificationHelper.checkOrCreateDefaultChannel();
6260
}
6361

64-
65-
6662
@Override
6763
public String getName() {
6864
return "RNPushNotification";

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationAttributes.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ public class RNPushNotificationAttributes {
2828
private static final String BIG_PICTURE_URL = "bigPictureUrl";
2929
private static final String SHORTCUT_ID = "shortcutId";
3030
private static final String CHANNEL_ID = "channelId";
31-
private static final String CHANNEL_NAME = "channelName";
32-
private static final String CHANNEL_DESCRIPTION = "channelDescription";
3331
private static final String NUMBER = "number";
3432
private static final String SOUND = "sound";
3533
private static final String COLOR = "color";
@@ -68,8 +66,6 @@ public class RNPushNotificationAttributes {
6866
private final String shortcutId;
6967
private final String number;
7068
private final String channelId;
71-
private final String channelName;
72-
private final String channelDescription;
7369
private final String sound;
7470
private final String color;
7571
private final String group;
@@ -108,8 +104,6 @@ public RNPushNotificationAttributes(Bundle bundle) {
108104
shortcutId = bundle.getString(SHORTCUT_ID);
109105
number = bundle.getString(NUMBER);
110106
channelId = bundle.getString(CHANNEL_ID);
111-
channelName = bundle.getString(CHANNEL_NAME);
112-
channelDescription = bundle.getString(CHANNEL_DESCRIPTION);
113107
sound = bundle.getString(SOUND);
114108
color = bundle.getString(COLOR);
115109
group = bundle.getString(GROUP);
@@ -150,8 +144,6 @@ private RNPushNotificationAttributes(JSONObject jsonObject) {
150144
shortcutId = jsonObject.has(SHORTCUT_ID) ? jsonObject.getString(SHORTCUT_ID) : null;
151145
number = jsonObject.has(NUMBER) ? jsonObject.getString(NUMBER) : null;
152146
channelId = jsonObject.has(CHANNEL_ID) ? jsonObject.getString(CHANNEL_ID) : null;
153-
channelName = jsonObject.has(CHANNEL_NAME) ? jsonObject.getString(CHANNEL_NAME) : null;
154-
channelDescription = jsonObject.has(CHANNEL_DESCRIPTION) ? jsonObject.getString(CHANNEL_DESCRIPTION) : null;
155147
sound = jsonObject.has(SOUND) ? jsonObject.getString(SOUND) : null;
156148
color = jsonObject.has(COLOR) ? jsonObject.getString(COLOR) : null;
157149
group = jsonObject.has(GROUP) ? jsonObject.getString(GROUP) : null;
@@ -249,8 +241,6 @@ public Bundle toBundle() {
249241
bundle.putString(SHORTCUT_ID, shortcutId);
250242
bundle.putString(NUMBER, number);
251243
bundle.putString(CHANNEL_ID, channelId);
252-
bundle.putString(CHANNEL_NAME, channelName);
253-
bundle.putString(CHANNEL_DESCRIPTION, channelDescription);
254244
bundle.putString(SOUND, sound);
255245
bundle.putString(COLOR, color);
256246
bundle.putString(GROUP, group);
@@ -293,8 +283,6 @@ public JSONObject toJson() {
293283
jsonObject.put(SHORTCUT_ID, shortcutId);
294284
jsonObject.put(NUMBER, number);
295285
jsonObject.put(CHANNEL_ID, channelId);
296-
jsonObject.put(CHANNEL_NAME, channelName);
297-
jsonObject.put(CHANNEL_DESCRIPTION, channelDescription);
298286
jsonObject.put(SOUND, sound);
299287
jsonObject.put(COLOR, color);
300288
jsonObject.put(GROUP, group);
@@ -343,8 +331,6 @@ public String toString() {
343331
", shortcutId='" + shortcutId + '\'' +
344332
", number='" + number + '\'' +
345333
", channelId='" + channelId + '\'' +
346-
", channelName='" + channelId + '\'' +
347-
", channelDescription='" + channelDescription + '\'' +
348334
", sound='" + sound + '\'' +
349335
", color='" + color + '\'' +
350336
", group='" + group + '\'' +

android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotificationBootEventReceiver.java

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,30 @@ public class RNPushNotificationBootEventReceiver extends BroadcastReceiver {
2020
public void onReceive(Context context, Intent intent) {
2121
Log.i(LOG_TAG, "RNPushNotificationBootEventReceiver loading scheduled notifications");
2222

23-
if ("android.intent.action.BOOT_COMPLETED".equals(intent.getAction())) {
24-
SharedPreferences sharedPreferences = context.getSharedPreferences(RNPushNotificationHelper.PREFERENCES_KEY, Context.MODE_PRIVATE);
25-
Set<String> ids = sharedPreferences.getAll().keySet();
26-
27-
Application applicationContext = (Application) context.getApplicationContext();
28-
RNPushNotificationHelper rnPushNotificationHelper = new RNPushNotificationHelper(applicationContext);
29-
30-
for (String id : ids) {
31-
try {
32-
String notificationAttributesJson = sharedPreferences.getString(id, null);
33-
if (notificationAttributesJson != null) {
34-
RNPushNotificationAttributes notificationAttributes = RNPushNotificationAttributes.fromJson(notificationAttributesJson);
35-
36-
if (notificationAttributes.getFireDate() < System.currentTimeMillis()) {
37-
Log.i(LOG_TAG, "RNPushNotificationBootEventReceiver: Showing notification for " +
38-
notificationAttributes.getId());
39-
rnPushNotificationHelper.sendToNotificationCentre(notificationAttributes.toBundle());
40-
} else {
41-
Log.i(LOG_TAG, "RNPushNotificationBootEventReceiver: Scheduling notification for " +
42-
notificationAttributes.getId());
43-
rnPushNotificationHelper.sendNotificationScheduledCore(notificationAttributes.toBundle());
44-
}
23+
SharedPreferences sharedPreferences = context.getSharedPreferences(RNPushNotificationHelper.PREFERENCES_KEY, Context.MODE_PRIVATE);
24+
Set<String> ids = sharedPreferences.getAll().keySet();
25+
26+
Application applicationContext = (Application) context.getApplicationContext();
27+
RNPushNotificationHelper rnPushNotificationHelper = new RNPushNotificationHelper(applicationContext);
28+
29+
for (String id : ids) {
30+
try {
31+
String notificationAttributesJson = sharedPreferences.getString(id, null);
32+
if (notificationAttributesJson != null) {
33+
RNPushNotificationAttributes notificationAttributes = RNPushNotificationAttributes.fromJson(notificationAttributesJson);
34+
35+
if (notificationAttributes.getFireDate() < System.currentTimeMillis()) {
36+
Log.i(LOG_TAG, "RNPushNotificationBootEventReceiver: Showing notification for " +
37+
notificationAttributes.getId());
38+
rnPushNotificationHelper.sendToNotificationCentre(notificationAttributes.toBundle());
39+
} else {
40+
Log.i(LOG_TAG, "RNPushNotificationBootEventReceiver: Scheduling notification for " +
41+
notificationAttributes.getId());
42+
rnPushNotificationHelper.sendNotificationScheduledCore(notificationAttributes.toBundle());
4543
}
46-
} catch (Exception e) {
47-
Log.e(LOG_TAG, "Problem with boot receiver loading notification " + id, e);
4844
}
45+
} catch (Exception e) {
46+
Log.e(LOG_TAG, "Problem with boot receiver loading notification " + id, e);
4947
}
5048
}
5149
}

0 commit comments

Comments
 (0)