Skip to content

Commit

Permalink
Sync with upstream (#3)
Browse files Browse the repository at this point in the history
* Make sure to import PushNotificationIOS from react-native first

* typo

* Delete versions.yml

* Update push-notification-ios to 1.2.0

Version 1.1.0 giving a `No known class method for selector 'didReceiveNotificationResponse'`error

* Add a Log.e() on fail.

* Add option in AndroidManifest to allow/remove notification in foreground (remote-only)

* Change the documentation of onNotification.

* Implement `onNewToken` for Firebase.

* Add an example with sound in project example.

* feat: ✨ Revoke Token method

Added the Revoke Token method to Android only. With this method is possible to generate a new token after a logout case with revoking.

* docs: 📝 Revoke Token method documentation

Added Revoke Token method descprition at Android Only Methods section

* chore: Added Revoke Token button

Updated example with the new Revoke Token method, adding a button, alert feedback and necessary calls

* Allow numbers for `number` and `id` in Android.

* chore: 👌 Revoke Token method renamed to Abandon Permissions

* chore: 👌 Updated to new Abandon Permissions method name

The Revoke Token method has been renamed to Abandon Permissions method

* docs: 📝 Updated with new Abandon Permissions method

Renamed Revoked Method to Abandon Permissions method. The method from iOS only section was removed and added a new general method section with the new method

* Changes in example Application.

* Use directly the callNative for `abandonPermissions`.

* Put deleteInstanceId() in a separate thread.

* Bump to version 3.4.0.

* Prevent crash for NaN.

* Update CHANGELOG.md.

* Prevent sound to be mute in default state.

* Missing change on variable name.

* feat: multiple push providers

fix: fix naming

fix: more fixes

fix: more fixes

fix: add activity service

fix: update naming

* Change from 18 months to 1 year

* feat: explicitly override onNewToken

* zo0r#1431

* Move back onNewToken to Firebase service.

* Bump to 3.5.0.

* Switch from support library to androidx.
zo0r#1449

* Bump to 3.5.1.

* Update README.md

* Fix sounds volume and DND is ignored.
Fix zo0r#1455 `onNotification fires every time when the app goes from background to foreground`

* Remove extra interface.

* Bump to 3.5.2.

* Fix changelog, wrong issue mentioned.

Co-authored-by: Hans Govind <hans@exove.fi>
Co-authored-by: Andrew Tremblay (Pear profile) <43054023+andrewtremblay-pear@users.noreply.github.com>
Co-authored-by: Boris Tacyniak <boris.tacyniak@free.fr>
Co-authored-by: willnaoosmit <55159911+willnaoosmit@users.noreply.github.com>
Co-authored-by: Gabriel Consalter <consaltergabriel@gmail.com>
Co-authored-by: sarah denaci <sarah@gridwise.io>
Co-authored-by: Taymer Ragazzini <tragazzini@gmail.com>
  • Loading branch information
8 people authored Jun 24, 2020
1 parent 0727fa7 commit 19b00e7
Show file tree
Hide file tree
Showing 20 changed files with 493 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/stale.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ jobs:
repo-token: ${{ secrets.GITHUB_TOKEN }}
stale-issue-message: "This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions."
stale-pr-message: "This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 30 days if no further activity occurs. Thank you for your contributions."
days-before-stale: 560
days-before-stale: 365
days-before-close: 30
operations-per-run: 30
15 changes: 0 additions & 15 deletions .github/workflows/versions.yml

This file was deleted.

45 changes: 45 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,51 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

### Fixed

## [3.5.2] - 2020-05-25

### Fixed

- (Android) Sounds are playing even in Do Not Disturb [#1432](https://github.com/zo0r/react-native-push-notification/issues/1432#issuecomment-633367111)
- (Android) onNotification fires every time when the app goes from background to foreground [#1455](https://github.com/zo0r/react-native-push-notification/issues/1455)
- (Android) java.lang.NullPointerException: Attempt to invoke virtual method 'void com.dieam.reactnativepushnotification.modules.d.c(android.os.Bundle)' on a null object reference [#1431](https://github.com/zo0r/react-native-push-notification/issues/1431#issuecomment-633315150)

## [3.5.1] - 2020-05-20

### Fixed

- (Android) When updating 3.4 to 3.5, unable to compile Android [#1449](https://github.com/zo0r/react-native-push-notification/pull/1449)

## [3.5.0] - 2020-05-20

### Features

- (Android) Enables the ability to support multiple push providers [#1445](https://github.com/zo0r/react-native-push-notification/pull/1445)

### Fixed

- (Android) No sound on notifications [#1432](https://github.com/zo0r/react-native-push-notification/issues/1432)
- (Android) onNotification is not calling when app is in background [#1446](https://github.com/zo0r/react-native-push-notification/pull/1446)
- (Android) `number` and `id` do not crash if NaN is passed in Android.

## [3.4.0] - 2020-05-08

### Features

- (Android) Call `onRegister` when [Firebase renew token](<https://firebase.google.com/docs/reference/android/com/google/firebase/messaging/FirebaseMessagingService#onNewToken(java.lang.String)>).
- (Android) Added Abandon Permissions method to Android [#1425](https://github.com/zo0r/react-native-push-notification/pull/1425)
- (Android) Add a new key in `AndroidManifest.xml` to allow/remove notification in foreground.

```xml
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="false"/>
```

### Fixed

- (Android) `number` and `id` are now correctly handled as number in Android.
- (iOS) Update push-notification-ios to 1.2.0 [#1410](https://github.com/zo0r/react-native-push-notification/pull/1410)
- Make sure to import PushNotificationIOS from react-native first [#617](https://github.com/zo0r/react-native-push-notification/pull/617)

## [3.3.1] - 2020-05-01

### Fixed
Expand Down
22 changes: 16 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ In your `android/app/src/main/AndroidManifest.xml`
android:value="YOUR NOTIFICATION CHANNEL NAME"/>
<meta-data android:name="com.dieam.reactnativepushnotification.notification_channel_description"
android:value="YOUR NOTIFICATION CHANNEL DESCRIPTION"/>

<!-- Change the value to true to enable pop-up for in foreground (remote-only, for local use ignoreInForeground) -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_foreground"
android:value="false"/>
<!-- Change the resource name to your App's accent color - or any other color you want -->
<meta-data android:name="com.dieam.reactnativepushnotification.notification_color"
android:resource="@color/white"/> <!-- or @android:color/{name} to use a standard color -->
Expand Down Expand Up @@ -199,6 +203,7 @@ public class MainApplication extends Application implements ReactApplication {
## Usage

```javascript
import PushNotificationIOS from "@react-native-community/push-notification-ios";
var PushNotification = require("react-native-push-notification");

PushNotification.configure({
Expand All @@ -207,13 +212,13 @@ PushNotification.configure({
console.log("TOKEN:", token);
},

// (required) Called when a remote or local notification is opened or received
// (required) Called when a remote is received or opened, or local notification is opened
onNotification: function (notification) {
console.log("NOTIFICATION:", notification);

// process the notification

// required on iOS only (see fetchCompletionHandler docs: https://github.com/react-native-community/react-native-push-notification-ios)
// (required) Called when a remote is received or opened, or local notification is opened
notification.finish(PushNotificationIOS.FetchResult.NoData);
},

Expand Down Expand Up @@ -269,7 +274,7 @@ EXAMPLE:
```javascript
PushNotification.localNotification({
/* Android Only Properties */
id: "0", // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
id: 0, // (optional) Valid unique 32 bit integer specified as string. default: Autogenerated Unique ID
ticker: "My Notification Ticker", // (optional)
autoCancel: true, // (optional) default: true
largeIcon: "ic_launcher", // (optional) default: "ic_launcher"
Expand Down Expand Up @@ -413,6 +418,11 @@ Removes the specified notifications from Notification Center
| ----------- | ----- | -------- | ---------------------------------- |
| identifiers | array | Yes | Array of notification identifiers. |


## Abandon Permissions

`PushNotification.abandonPermissions()` Revokes the current token and unregister for all remote notifications received via APNS or FCM.

## Notification priority

(optional) Specify `priority` to set priority of notification. Default value: "high"
Expand Down Expand Up @@ -468,7 +478,7 @@ https://developer.android.com/training/monitoring-device-state/doze-standby

## Repeating Notifications

(optional) Specify `repeatType` and optionally `repeatTime` while scheduling the local notification. Check the local notification example above.
(optional) Specify `repeatType` and optionally `repeatTime` (Android-only) while scheduling the local notification. Check the local notification example above.

Property `repeatType` could be one of `month`, `week`, `day`, `hour`, `minute`, `time`. If specified as time, it should be accompanied by one more parameter `repeatTime` which should the number of milliseconds between each interval.

Expand Down Expand Up @@ -527,6 +537,8 @@ Same parameters as `PushNotification.localNotification()`

`PushNotification.subscribeToTopic(topic: string)` Subscribe to a topic (works only with Firebase)

`PushNotification.unsubscribeFromTopic(topic: string)` Unsubscribe from a topic (works only with Firebase)

## Checking Notification Permissions

`PushNotification.checkPermissions(callback: Function)` Check permissions
Expand All @@ -540,5 +552,3 @@ Same parameters as `PushNotification.localNotification()`
## iOS Only Methods

`PushNotification.getApplicationIconBadgeNumber(callback: Function)` Get badge number

`PushNotification.abandonPermissions()` Unregister for all remote notifications received via Apple Push Notification service.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
Expand Down Expand Up @@ -80,6 +81,8 @@ private Bundle getBundleFromIntent(Intent intent) {
}
return bundle;
}

@Override
public void onNewIntent(Intent intent) {
Bundle bundle = this.getBundleFromIntent(intent);
if (bundle != null) {
Expand Down Expand Up @@ -129,6 +132,7 @@ public void requestPermissions() {
@Override
public void onComplete(@NonNull Task<InstanceIdResult> task) {
if (!task.isSuccessful()) {
Log.e(LOG_TAG, "exception", task.getException());
return;
}

Expand Down Expand Up @@ -257,4 +261,22 @@ public void getDeliveredNotifications(Callback callback) {
public void removeDeliveredNotifications(ReadableArray identifiers) {
mRNPushNotificationHelper.clearDeliveredNotifications(identifiers);
}

@ReactMethod
/**
* Unregister for all remote notifications received
*/
public void abandonPermissions() {
new Thread(new Runnable() {
@Override
public void run() {
try {
FirebaseInstanceId.getInstance().deleteInstanceId();
Log.i(LOG_TAG, "InstanceID deleted");
} catch (IOException e) {
Log.e(LOG_TAG, "exception", e);
}
}
}).start();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
class RNPushNotificationConfig {
private static final String KEY_CHANNEL_NAME = "com.dieam.reactnativepushnotification.notification_channel_name";
private static final String KEY_CHANNEL_DESCRIPTION = "com.dieam.reactnativepushnotification.notification_channel_description";
private static final String KEY_NOTIFICATION_FOREGROUND = "com.dieam.reactnativepushnotification.notification_foreground";
private static final String KEY_NOTIFICATION_COLOR = "com.dieam.reactnativepushnotification.notification_color";

private static Bundle metadata;
Expand Down Expand Up @@ -53,6 +54,7 @@ public String getChannelDescription() {
// Default
return "";
}

public int getNotificationColor() {
try {
int resourceId = metadata.getInt(KEY_NOTIFICATION_COLOR);
Expand All @@ -63,4 +65,14 @@ public int getNotificationColor() {
// Default
return -1;
}

public boolean getNotificationForeground() {
try {
return metadata.getBoolean(KEY_NOTIFICATION_FOREGROUND, false);
} catch (Exception e) {
Log.w(RNPushNotification.LOG_TAG, "Unable to find " + KEY_NOTIFICATION_FOREGROUND + " in manifest. Falling back to default");
}
// Default
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,19 @@ private AlarmManager getAlarmManager() {
}

private PendingIntent toScheduleNotificationIntent(Bundle bundle) {
int notificationID = Integer.parseInt(bundle.getString("id"));
try {
int notificationID = Integer.parseInt(bundle.getString("id"));

Intent notificationIntent = new Intent(context, RNPushNotificationPublisher.class);
notificationIntent.putExtra(RNPushNotificationPublisher.NOTIFICATION_ID, notificationID);
notificationIntent.putExtras(bundle);
Intent notificationIntent = new Intent(context, RNPushNotificationPublisher.class);
notificationIntent.putExtra(RNPushNotificationPublisher.NOTIFICATION_ID, notificationID);
notificationIntent.putExtras(bundle);

return PendingIntent.getBroadcast(context, notificationID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
return PendingIntent.getBroadcast(context, notificationID, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
} catch (Exception e) {
Log.e(LOG_TAG, "Unable to parse Notification ID", e);
}

return null;
}

public void sendNotificationScheduled(Bundle bundle) {
Expand Down Expand Up @@ -145,6 +151,10 @@ public void sendNotificationScheduledCore(Bundle bundle) {
// notification to the user
PendingIntent pendingIntent = toScheduleNotificationIntent(bundle);

if(pendingIntent == null) {
return;
}

Log.d(LOG_TAG, String.format("Setting a notification with id %s at time %s",
bundle.getString("id"), Long.toString(fireDate)));
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
Expand Down Expand Up @@ -367,11 +377,13 @@ public void sendToNotificationCentre(Bundle bundle) {
}

soundUri = Uri.parse("android.resource://" + context.getPackageName() + "/" + resId);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // API 26 and higher
channel_id = channel_id + "-" + soundName;
}
}
} else {
soundName = "default";
}

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { // API 26 and higher
channel_id = channel_id + "-" + soundName;
}

notification.setSound(soundUri);
Expand Down Expand Up @@ -658,7 +670,11 @@ private void cancelScheduledNotification(String notificationIDString) {
// remove it from the alarm manger schedule
Bundle b = new Bundle();
b.putString("id", notificationIDString);
getAlarmManager().cancel(toScheduleNotificationIntent(b));
PendingIntent pendingIntent = toScheduleNotificationIntent(b);

if(pendingIntent != null) {
getAlarmManager().cancel(pendingIntent);
}

if (scheduledNotificationsPersistence.contains(notificationIDString)) {
// remove it from local storage
Expand All @@ -672,7 +688,11 @@ private void cancelScheduledNotification(String notificationIDString) {
// removed it from the notification center
NotificationManager notificationManager = notificationManager();

notificationManager.cancel(Integer.parseInt(notificationIDString));
try {
notificationManager.cancel(Integer.parseInt(notificationIDString));
} catch (Exception e) {
Log.e(LOG_TAG, "Unable to parse Notification ID " + notificationIDString, e);
}
}

private NotificationManager notificationManager() {
Expand All @@ -691,10 +711,15 @@ public void checkOrCreateDefaultChannel() {
NotificationManager manager = notificationManager();

int importance = NotificationManager.IMPORTANCE_HIGH;
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

// Instanciate a default channel with default sound.
String channel_id_sound = NOTIFICATION_CHANNEL_ID + "-default-" + importance + "-" + DEFAULT_VIBRATION;
checkOrCreateChannel(manager, channel_id_sound, soundUri, importance, new long[] {0, DEFAULT_VIBRATION});

String channel_id = NOTIFICATION_CHANNEL_ID + "-" + importance + "-" + DEFAULT_VIBRATION;

checkOrCreateChannel(manager, channel_id, null, importance, new long[] {0, DEFAULT_VIBRATION});
// Instanciate a default channel without sound defined for backward compatibility.
String channel_id_no_sound = NOTIFICATION_CHANNEL_ID + "-" + importance + "-" + DEFAULT_VIBRATION;
checkOrCreateChannel(manager, channel_id_no_sound, null, importance, new long[] {0, DEFAULT_VIBRATION});
}

private void checkOrCreateChannel(NotificationManager manager, String channel_id, Uri soundUri, int importance, long[] vibratePattern) {
Expand All @@ -716,7 +741,7 @@ private void checkOrCreateChannel(NotificationManager manager, String channel_id
if (soundUri != null) {
AudioAttributes audioAttributes = new AudioAttributes.Builder()
.setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION)
.setUsage(AudioAttributes.USAGE_ALARM)
.setUsage(AudioAttributes.USAGE_NOTIFICATION)
.build();

channel.setSound(soundUri, audioAttributes);
Expand Down
Loading

0 comments on commit 19b00e7

Please sign in to comment.