diff --git a/README.md b/README.md index 34f7c27b6..8f80c372a 100644 --- a/README.md +++ b/README.md @@ -413,6 +413,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" @@ -540,5 +545,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. diff --git a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java index 05a2e45c5..cac459a95 100644 --- a/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java +++ b/android/src/main/java/com/dieam/reactnativepushnotification/modules/RNPushNotification.java @@ -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; @@ -258,4 +259,17 @@ public void getDeliveredNotifications(Callback callback) { public void removeDeliveredNotifications(ReadableArray identifiers) { mRNPushNotificationHelper.clearDeliveredNotifications(identifiers); } + + @ReactMethod + /** + * Unregister for all remote notifications received + */ + public void abandonPermissions() { + try { + FirebaseInstanceId.getInstance().deleteInstanceId(); + } catch (IOException e) { + Log.e(LOG_TAG, "exception", e); + return; + } + } } diff --git a/component/index.android.js b/component/index.android.js index d9e3424da..13a442ead 100644 --- a/component/index.android.js +++ b/component/index.android.js @@ -61,10 +61,6 @@ NotificationsComponent.prototype.setApplicationIconBadgeNumber = function(number RNPushNotification.setApplicationIconBadgeNumber(number); }; -NotificationsComponent.prototype.abandonPermissions = function() { - /* Void */ -}; - NotificationsComponent.prototype.checkPermissions = function(callback) { RNPushNotification.checkPermissions().then(alert => callback({ alert })); }; @@ -131,6 +127,10 @@ NotificationsComponent.prototype.removeDeliveredNotifications = function(identif RNPushNotification.removeDeliveredNotifications(identifiers); } +NotificationsComponent.prototype.abandonPermissions = function() { + RNPushNotification.abandonPermissions(); +} + module.exports = { state: false, component: new NotificationsComponent() diff --git a/example/App.js b/example/App.js index 67675556d..667924a38 100644 --- a/example/App.js +++ b/example/App.js @@ -84,6 +84,17 @@ export default class App extends Component { }}> Request Permissions + { + this.notif.abandonPermissions(); + Alert.alert( + 'Abandon Permissions', + 'Reload the app to register again with a new token' + ); + }}> + Abandon Permissions + diff --git a/example/NotifService.js b/example/NotifService.js index 5e4b19e90..82b043c02 100644 --- a/example/NotifService.js +++ b/example/NotifService.js @@ -116,4 +116,8 @@ export default class NotifService { cancelAll() { PushNotification.cancelAllLocalNotifications(); } + + abandonPermissions() { + PushNotification.abandonPermissions(); + } } diff --git a/index.js b/index.js index fdd2e3250..c409b3e8d 100644 --- a/index.js +++ b/index.js @@ -188,6 +188,11 @@ Notifications.localNotificationSchedule = function(details) { } }; +/* Abandon Permissions */ +Notifications.abandonPermissions = function() { + this.handler.abandonPermissions(); +} + /* Internal Functions */ Notifications._onRegister = function(token) { if ( this.onRegister !== false ) { @@ -315,10 +320,6 @@ Notifications.popInitialNotification = function(handler) { }); }; -Notifications.abandonPermissions = function() { - return this.callNative('abandonPermissions', arguments); -}; - Notifications.checkPermissions = function() { return this.callNative('checkPermissions', arguments); };