Skip to content

Commit

Permalink
Upgrade to 8.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Dallas62 committed Aug 19, 2021
1 parent 6a81fba commit 17ad0ae
Show file tree
Hide file tree
Showing 9 changed files with 62 additions and 99 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,22 @@ This project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html

### Fixed

## [8.0.0] 2021-08-19

### Breaking changes

- `userInfo` is no more populated with the `id` of the notification, initialy included to cancel scheduled notifications. This change will probably not impact you.
- Rename `cancelLocalNotifications` to `cancelLocalNotification` (deprecation notice).

### Features

- (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)
- `picture` is now support for both Android and iOS, (alias of `bigPictureUrl` for Android).

### Fixed

- (Android): Fix bug cancelLocalNotifications() does not work on Android [#2100](https://github.com/zo0r/react-native-push-notification/issues/2100)

## [7.4.0] 2021-06-24

### Features
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,7 @@ PushNotification.localNotification({
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
title: "My Notification Title", // (optional)
message: "My Notification Message", // (required)
picture: "https://www.example.tld/picture.jpg", // (optional) Display an picture with the notification, alias of `bigPictureUrl` for Android. default: undefined
userInfo: {}, // (optional) default: {} (using null throws a JSON value '<null>' error)
playSound: false, // (optional) 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)
Expand Down Expand Up @@ -481,7 +482,7 @@ PushNotification.deleteChannel(channel_id);

## Cancelling notifications

### 1) cancelLocalNotifications
### 1) cancelLocalNotification

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

Expand All @@ -491,11 +492,9 @@ PushNotification.localNotification({
id: '123'
...
});
PushNotification.cancelLocalNotifications({id: '123'});
PushNotification.cancelLocalNotification('123');
```

**iOS: `userInfo` is populated `id` if not defined this allow the previous method**

### 2) cancelAllLocalNotifications

```javascript
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,11 @@ public void cancelAllLocalNotifications() {

@ReactMethod
/**
* Cancel scheduled notifications, and removes notifications from the notification centre.
* Cancel scheduled notification, and remove notification from the notification centre.
*
*/
public void cancelLocalNotifications(ReadableMap userInfo) {
mRNPushNotificationHelper.cancelScheduledNotification(userInfo);
public void cancelLocalNotification(String notification_id) {
mRNPushNotificationHelper.cancelScheduledNotification(notification_id);
}

@ReactMethod
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,62 +190,6 @@ public static RNPushNotificationAttributes fromJson(String notificationAttribute
return new RNPushNotificationAttributes(jsonObject);
}

/**
* User to find notifications:
* <p>
*
* @param userInfo map of fields to match
* @return true all fields in userInfo object match, false otherwise
*/
public boolean matches(ReadableMap userInfo) {
try {
if(this.userInfo == null) {
return false;
}

JSONObject jsonObject = new JSONObject(this.userInfo);

ReadableMapKeySetIterator iterator = userInfo.keySetIterator();
while (iterator.hasNextKey()) {
String key = iterator.nextKey();

if (!jsonObject.has(key))
return false;

switch (userInfo.getType(key)) {
case Null: {
if (jsonObject.get(key) != null)
return false;
break;
}
case Boolean: {
if (userInfo.getBoolean(key) != jsonObject.getBoolean(key))
return false;
break;
}
case Number: {
if ((userInfo.getDouble(key) != jsonObject.getDouble(key)) && (userInfo.getInt(key) != jsonObject.getInt(key)))
return false;
break;
}
case String: {
if (!userInfo.getString(key).equals(jsonObject.getString(key)))
return false;
break;
}
case Map:
return false;//there are no maps in the jsonObject
case Array:
return false;//there are no arrays in the jsonObject
}
}
} catch(JSONException e) {
return false;
}

return true;
}

public Bundle toBundle() {
Bundle bundle = new Bundle();
bundle.putString(ID, id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -775,23 +775,7 @@ public void cancelAllScheduledNotifications() {
}
}

public void cancelScheduledNotification(ReadableMap userInfo) {
for (String id : scheduledNotificationsPersistence.getAll().keySet()) {
try {
String notificationAttributesJson = scheduledNotificationsPersistence.getString(id, null);
if (notificationAttributesJson != null) {
RNPushNotificationAttributes notificationAttributes = fromJson(notificationAttributesJson);
if (notificationAttributes.matches(userInfo)) {
cancelScheduledNotification(id);
}
}
} catch (JSONException e) {
Log.w(LOG_TAG, "Problem dealing with scheduled notification " + id, e);
}
}
}

private void cancelScheduledNotification(String notificationIDString) {
public void cancelScheduledNotification(String notificationIDString) {
Log.i(LOG_TAG, "Cancelling notification: " + notificationIDString);

// remove it from the alarm manger schedule
Expand Down
2 changes: 1 addition & 1 deletion example/NotifService.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default class NotifService {
}

cancelNotif() {
PushNotification.cancelLocalNotifications({id: '' + this.lastId});
PushNotification.cancelLocalNotification(this.lastId);
}

cancelAll() {
Expand Down
4 changes: 2 additions & 2 deletions example/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ PODS:
- React-Core (= 0.63.3)
- React-cxxreact (= 0.63.3)
- React-jsi (= 0.63.3)
- RNCPushNotificationIOS (1.8.0):
- RNCPushNotificationIOS (1.9.0):
- React-Core
- Yoga (1.14.0)

Expand Down Expand Up @@ -367,7 +367,7 @@ SPEC CHECKSUMS:
React-RCTText: 65a6de06a7389098ce24340d1d3556015c38f746
React-RCTVibration: 8e9fb25724a0805107fc1acc9075e26f814df454
ReactCommon: 4167844018c9ed375cc01a843e9ee564399e53c3
RNCPushNotificationIOS: 61a7c72bd1ebad3568025957d001e0f0e7b32191
RNCPushNotificationIOS: 5bffde624d1fd15bfc8b2fd202b012a517a6dc9b
Yoga: 7d13633d129fd179e01b8953d38d47be90db185a

PODFILE CHECKSUM: 9f7efe26f7ad5184f28ac62478069370942924e2
Expand Down
48 changes: 34 additions & 14 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,6 @@ Notifications.localNotification = function({...details}) {
}
}

if (details.userInfo) {
details.userInfo.id = details.userInfo.id || details.id;
} else {
details.userInfo = {id: details.id};
}

if (Platform.OS === 'ios') {
// https://developer.apple.com/reference/uikit/uilocalnotification

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

if(details.picture) {
details.userInfo = details.userInfo || {};
details.userInfo.image = details.picture;
}

// for valid fields see: https://github.com/react-native-push-notification-ios/push-notification-ios#addnotificationrequest

this.handler.addNotificationRequest({
Expand Down Expand Up @@ -212,6 +211,10 @@ Notifications.localNotification = function({...details}) {
details.userInfo = JSON.stringify(details.userInfo);
}

if(details.picture && !details.bigPictureUrl) {
details.bigPictureUrl = details.picture;
}

this.handler.presentLocalNotification(details);
}
};
Expand All @@ -236,19 +239,18 @@ Notifications.localNotificationSchedule = function({...details}) {
}
}

if (details.userInfo) {
details.userInfo.id = details.userInfo.id || details.id;
} else {
details.userInfo = {id: details.id};
}

if (Platform.OS === 'ios') {
let soundName = details.soundName ? details.soundName : 'default'; // play sound (and vibrate) as default behaviour

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

if(details.picture) {
details.userInfo = details.userInfo || {};
details.userInfo.image = details.picture;
}

const iosDetails = {
id: (!details.id ? Math.floor(Math.random() * Math.pow(2, 32)).toString() : details.id),
fireDate: details.date.toISOString(),
Expand Down Expand Up @@ -296,6 +298,10 @@ Notifications.localNotificationSchedule = function({...details}) {
details.userInfo = JSON.stringify(details.userInfo);
}

if(details.picture && !details.bigPictureUrl) {
details.bigPictureUrl = details.picture;
}

details.fireDate = details.date.getTime();
delete details.date;
// ignore iOS only repeatType
Expand Down Expand Up @@ -472,10 +478,24 @@ Notifications.scheduleLocalNotification = function() {
};

Notifications.cancelLocalNotifications = function(userInfo) {
console.warn('This method is now deprecated, please use `cancelLocalNotification` (remove the ending `s`).');

return this.cancelLocalNotification(userInfo);
};

Notifications.cancelLocalNotification = function(notificationId) {
if(typeof notificationId === 'object') {
notificationId = notificationId?.id;
}

if(typeof notificationId === 'number') {
notificationId = '' + notificationId;
}

if ( Platform.OS === 'ios' ) {
return this.callNative('removePendingNotificationRequests', [[userInfo.id]]);
return this.callNative('removePendingNotificationRequests', [[notificationId]]);
} else {
return this.callNative('cancelLocalNotifications', [userInfo]);
return this.callNative('cancelLocalNotification', [notificationId]);
}
};

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-push-notification",
"version": "7.4.0",
"version": "8.0.0",
"description": "React Native Local and Remote Notifications",
"main": "index.js",
"scripts": {
Expand All @@ -24,7 +24,7 @@
"url": "git+ssh://git@github.com:zo0r/react-native-push-notification.git"
},
"peerDependencies": {
"@react-native-community/push-notification-ios": "^1.8.0",
"@react-native-community/push-notification-ios": "^1.9.0",
"react-native": ">=0.33"
},
"author": "zo0r <http://zo0r.me>",
Expand Down

0 comments on commit 17ad0ae

Please sign in to comment.