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

Commit 17ad0ae

Browse files
committed
Upgrade to 8.0.0
1 parent 6a81fba commit 17ad0ae

File tree

9 files changed

+62
-99
lines changed

9 files changed

+62
-99
lines changed

CHANGELOG.md

+16
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,22 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html
1212

1313
### Fixed
1414

15+
## [8.0.0] 2021-08-19
16+
17+
### Breaking changes
18+
19+
- `userInfo` is no more populated with the `id` of the notification, initialy included to cancel scheduled notifications. This change will probably not impact you.
20+
- Rename `cancelLocalNotifications` to `cancelLocalNotification` (deprecation notice).
21+
22+
### Features
23+
24+
- (iOS) upgrade `@react-native-community/push-notification-ios` to version [1.9.0](https://github.com/react-native-push-notification/ios/releases/tag/v1.9.0)
25+
- `picture` is now support for both Android and iOS, (alias of `bigPictureUrl` for Android).
26+
27+
### Fixed
28+
29+
- (Android): Fix bug cancelLocalNotifications() does not work on Android [#2100](https://github.com/zo0r/react-native-push-notification/issues/2100)
30+
1531
## [7.4.0] 2021-06-24
1632

1733
### Features

README.md

+3-4
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,7 @@ PushNotification.localNotification({
342342
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
343343
title: "My Notification Title", // (optional)
344344
message: "My Notification Message", // (required)
345+
picture: "https://www.example.tld/picture.jpg", // (optional) Display an picture with the notification, alias of `bigPictureUrl` for Android. default: undefined
345346
userInfo: {}, // (optional) default: {} (using null throws a JSON value '<null>' error)
346347
playSound: false, // (optional) default: true
347348
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)
@@ -481,7 +482,7 @@ PushNotification.deleteChannel(channel_id);
481482

482483
## Cancelling notifications
483484

484-
### 1) cancelLocalNotifications
485+
### 1) cancelLocalNotification
485486

486487
The `id` parameter for `PushNotification.localNotification` is required for this operation. The id supplied will then be used for the cancel operation.
487488

@@ -491,11 +492,9 @@ PushNotification.localNotification({
491492
id: '123'
492493
...
493494
});
494-
PushNotification.cancelLocalNotifications({id: '123'});
495+
PushNotification.cancelLocalNotification('123');
495496
```
496497

497-
**iOS: `userInfo` is populated `id` if not defined this allow the previous method**
498-
499498
### 2) cancelAllLocalNotifications
500499

501500
```javascript

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -226,11 +226,11 @@ public void cancelAllLocalNotifications() {
226226

227227
@ReactMethod
228228
/**
229-
* Cancel scheduled notifications, and removes notifications from the notification centre.
229+
* Cancel scheduled notification, and remove notification from the notification centre.
230230
*
231231
*/
232-
public void cancelLocalNotifications(ReadableMap userInfo) {
233-
mRNPushNotificationHelper.cancelScheduledNotification(userInfo);
232+
public void cancelLocalNotification(String notification_id) {
233+
mRNPushNotificationHelper.cancelScheduledNotification(notification_id);
234234
}
235235

236236
@ReactMethod

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

-56
Original file line numberDiff line numberDiff line change
@@ -190,62 +190,6 @@ public static RNPushNotificationAttributes fromJson(String notificationAttribute
190190
return new RNPushNotificationAttributes(jsonObject);
191191
}
192192

193-
/**
194-
* User to find notifications:
195-
* <p>
196-
*
197-
* @param userInfo map of fields to match
198-
* @return true all fields in userInfo object match, false otherwise
199-
*/
200-
public boolean matches(ReadableMap userInfo) {
201-
try {
202-
if(this.userInfo == null) {
203-
return false;
204-
}
205-
206-
JSONObject jsonObject = new JSONObject(this.userInfo);
207-
208-
ReadableMapKeySetIterator iterator = userInfo.keySetIterator();
209-
while (iterator.hasNextKey()) {
210-
String key = iterator.nextKey();
211-
212-
if (!jsonObject.has(key))
213-
return false;
214-
215-
switch (userInfo.getType(key)) {
216-
case Null: {
217-
if (jsonObject.get(key) != null)
218-
return false;
219-
break;
220-
}
221-
case Boolean: {
222-
if (userInfo.getBoolean(key) != jsonObject.getBoolean(key))
223-
return false;
224-
break;
225-
}
226-
case Number: {
227-
if ((userInfo.getDouble(key) != jsonObject.getDouble(key)) && (userInfo.getInt(key) != jsonObject.getInt(key)))
228-
return false;
229-
break;
230-
}
231-
case String: {
232-
if (!userInfo.getString(key).equals(jsonObject.getString(key)))
233-
return false;
234-
break;
235-
}
236-
case Map:
237-
return false;//there are no maps in the jsonObject
238-
case Array:
239-
return false;//there are no arrays in the jsonObject
240-
}
241-
}
242-
} catch(JSONException e) {
243-
return false;
244-
}
245-
246-
return true;
247-
}
248-
249193
public Bundle toBundle() {
250194
Bundle bundle = new Bundle();
251195
bundle.putString(ID, id);

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

+1-17
Original file line numberDiff line numberDiff line change
@@ -775,23 +775,7 @@ public void cancelAllScheduledNotifications() {
775775
}
776776
}
777777

778-
public void cancelScheduledNotification(ReadableMap userInfo) {
779-
for (String id : scheduledNotificationsPersistence.getAll().keySet()) {
780-
try {
781-
String notificationAttributesJson = scheduledNotificationsPersistence.getString(id, null);
782-
if (notificationAttributesJson != null) {
783-
RNPushNotificationAttributes notificationAttributes = fromJson(notificationAttributesJson);
784-
if (notificationAttributes.matches(userInfo)) {
785-
cancelScheduledNotification(id);
786-
}
787-
}
788-
} catch (JSONException e) {
789-
Log.w(LOG_TAG, "Problem dealing with scheduled notification " + id, e);
790-
}
791-
}
792-
}
793-
794-
private void cancelScheduledNotification(String notificationIDString) {
778+
public void cancelScheduledNotification(String notificationIDString) {
795779
Log.i(LOG_TAG, "Cancelling notification: " + notificationIDString);
796780

797781
// remove it from the alarm manger schedule

example/NotifService.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ export default class NotifService {
157157
}
158158

159159
cancelNotif() {
160-
PushNotification.cancelLocalNotifications({id: '' + this.lastId});
160+
PushNotification.cancelLocalNotification(this.lastId);
161161
}
162162

163163
cancelAll() {

example/ios/Podfile.lock

+2-2
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ PODS:
245245
- React-Core (= 0.63.3)
246246
- React-cxxreact (= 0.63.3)
247247
- React-jsi (= 0.63.3)
248-
- RNCPushNotificationIOS (1.8.0):
248+
- RNCPushNotificationIOS (1.9.0):
249249
- React-Core
250250
- Yoga (1.14.0)
251251

@@ -367,7 +367,7 @@ SPEC CHECKSUMS:
367367
React-RCTText: 65a6de06a7389098ce24340d1d3556015c38f746
368368
React-RCTVibration: 8e9fb25724a0805107fc1acc9075e26f814df454
369369
ReactCommon: 4167844018c9ed375cc01a843e9ee564399e53c3
370-
RNCPushNotificationIOS: 61a7c72bd1ebad3568025957d001e0f0e7b32191
370+
RNCPushNotificationIOS: 5bffde624d1fd15bfc8b2fd202b012a517a6dc9b
371371
Yoga: 7d13633d129fd179e01b8953d38d47be90db185a
372372

373373
PODFILE CHECKSUM: 9f7efe26f7ad5184f28ac62478069370942924e2

index.js

+34-14
Original file line numberDiff line numberDiff line change
@@ -155,12 +155,6 @@ Notifications.localNotification = function({...details}) {
155155
}
156156
}
157157

158-
if (details.userInfo) {
159-
details.userInfo.id = details.userInfo.id || details.id;
160-
} else {
161-
details.userInfo = {id: details.id};
162-
}
163-
164158
if (Platform.OS === 'ios') {
165159
// https://developer.apple.com/reference/uikit/uilocalnotification
166160

@@ -170,6 +164,11 @@ Notifications.localNotification = function({...details}) {
170164
soundName = ''; // empty string results in no sound (and no vibration)
171165
}
172166

167+
if(details.picture) {
168+
details.userInfo = details.userInfo || {};
169+
details.userInfo.image = details.picture;
170+
}
171+
173172
// for valid fields see: https://github.com/react-native-push-notification-ios/push-notification-ios#addnotificationrequest
174173

175174
this.handler.addNotificationRequest({
@@ -212,6 +211,10 @@ Notifications.localNotification = function({...details}) {
212211
details.userInfo = JSON.stringify(details.userInfo);
213212
}
214213

214+
if(details.picture && !details.bigPictureUrl) {
215+
details.bigPictureUrl = details.picture;
216+
}
217+
215218
this.handler.presentLocalNotification(details);
216219
}
217220
};
@@ -236,19 +239,18 @@ Notifications.localNotificationSchedule = function({...details}) {
236239
}
237240
}
238241

239-
if (details.userInfo) {
240-
details.userInfo.id = details.userInfo.id || details.id;
241-
} else {
242-
details.userInfo = {id: details.id};
243-
}
244-
245242
if (Platform.OS === 'ios') {
246243
let soundName = details.soundName ? details.soundName : 'default'; // play sound (and vibrate) as default behaviour
247244

248245
if (details.hasOwnProperty('playSound') && !details.playSound) {
249246
soundName = ''; // empty string results in no sound (and no vibration)
250247
}
251248

249+
if(details.picture) {
250+
details.userInfo = details.userInfo || {};
251+
details.userInfo.image = details.picture;
252+
}
253+
252254
const iosDetails = {
253255
id: (!details.id ? Math.floor(Math.random() * Math.pow(2, 32)).toString() : details.id),
254256
fireDate: details.date.toISOString(),
@@ -296,6 +298,10 @@ Notifications.localNotificationSchedule = function({...details}) {
296298
details.userInfo = JSON.stringify(details.userInfo);
297299
}
298300

301+
if(details.picture && !details.bigPictureUrl) {
302+
details.bigPictureUrl = details.picture;
303+
}
304+
299305
details.fireDate = details.date.getTime();
300306
delete details.date;
301307
// ignore iOS only repeatType
@@ -472,10 +478,24 @@ Notifications.scheduleLocalNotification = function() {
472478
};
473479

474480
Notifications.cancelLocalNotifications = function(userInfo) {
481+
console.warn('This method is now deprecated, please use `cancelLocalNotification` (remove the ending `s`).');
482+
483+
return this.cancelLocalNotification(userInfo);
484+
};
485+
486+
Notifications.cancelLocalNotification = function(notificationId) {
487+
if(typeof notificationId === 'object') {
488+
notificationId = notificationId?.id;
489+
}
490+
491+
if(typeof notificationId === 'number') {
492+
notificationId = '' + notificationId;
493+
}
494+
475495
if ( Platform.OS === 'ios' ) {
476-
return this.callNative('removePendingNotificationRequests', [[userInfo.id]]);
496+
return this.callNative('removePendingNotificationRequests', [[notificationId]]);
477497
} else {
478-
return this.callNative('cancelLocalNotifications', [userInfo]);
498+
return this.callNative('cancelLocalNotification', [notificationId]);
479499
}
480500
};
481501

package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-native-push-notification",
3-
"version": "7.4.0",
3+
"version": "8.0.0",
44
"description": "React Native Local and Remote Notifications",
55
"main": "index.js",
66
"scripts": {
@@ -24,7 +24,7 @@
2424
"url": "git+ssh://[email protected]:zo0r/react-native-push-notification.git"
2525
},
2626
"peerDependencies": {
27-
"@react-native-community/push-notification-ios": "^1.8.0",
27+
"@react-native-community/push-notification-ios": "^1.9.0",
2828
"react-native": ">=0.33"
2929
},
3030
"author": "zo0r <http://zo0r.me>",

0 commit comments

Comments
 (0)