This repository was archived by the owner on Jan 14, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 6 files changed +43
-10
lines changed
android/src/main/java/com/dieam/reactnativepushnotification/modules Expand file tree Collapse file tree 6 files changed +43
-10
lines changed Original file line number Diff line number Diff line change @@ -418,6 +418,11 @@ Removes the specified notifications from Notification Center
418418| ----------- | ----- | -------- | ---------------------------------- |
419419| identifiers | array | Yes | Array of notification identifiers. |
420420
421+
422+ ## Abandon Permissions
423+
424+ ` PushNotification.abandonPermissions() ` Revokes the current token and unregister for all remote notifications received via APNS or FCM.
425+
421426## Notification priority
422427
423428(optional) Specify ` priority ` to set priority of notification. Default value: "high"
@@ -547,5 +552,3 @@ Same parameters as `PushNotification.localNotification()`
547552## iOS Only Methods
548553
549554` PushNotification.getApplicationIconBadgeNumber(callback: Function) ` Get badge number
550-
551- ` PushNotification.abandonPermissions() ` Unregister for all remote notifications received via Apple Push Notification service.
Original file line number Diff line number Diff line change 2525import com .facebook .react .bridge .ReadableMap ;
2626import com .facebook .react .bridge .WritableMap ;
2727
28+ import java .io .IOException ;
2829import java .util .HashMap ;
2930import java .util .Map ;
3031import java .util .Random ;
@@ -258,4 +259,17 @@ public void getDeliveredNotifications(Callback callback) {
258259 public void removeDeliveredNotifications (ReadableArray identifiers ) {
259260 mRNPushNotificationHelper .clearDeliveredNotifications (identifiers );
260261 }
262+
263+ @ ReactMethod
264+ /**
265+ * Unregister for all remote notifications received
266+ */
267+ public void abandonPermissions () {
268+ try {
269+ FirebaseInstanceId .getInstance ().deleteInstanceId ();
270+ } catch (IOException e ) {
271+ Log .e (LOG_TAG , "exception" , e );
272+ return ;
273+ }
274+ }
261275}
Original file line number Diff line number Diff line change @@ -61,10 +61,6 @@ NotificationsComponent.prototype.setApplicationIconBadgeNumber = function(number
6161 RNPushNotification . setApplicationIconBadgeNumber ( number ) ;
6262} ;
6363
64- NotificationsComponent . prototype . abandonPermissions = function ( ) {
65- /* Void */
66- } ;
67-
6864NotificationsComponent . prototype . checkPermissions = function ( callback ) {
6965 RNPushNotification . checkPermissions ( ) . then ( alert => callback ( { alert } ) ) ;
7066} ;
@@ -131,6 +127,10 @@ NotificationsComponent.prototype.removeDeliveredNotifications = function(identif
131127 RNPushNotification . removeDeliveredNotifications ( identifiers ) ;
132128}
133129
130+ NotificationsComponent . prototype . abandonPermissions = function ( ) {
131+ RNPushNotification . abandonPermissions ( ) ;
132+ }
133+
134134module . exports = {
135135 state : false ,
136136 component : new NotificationsComponent ( )
Original file line number Diff line number Diff line change @@ -98,6 +98,17 @@ export default class App extends Component {
9898 } } >
9999 < Text > Request Permissions</ Text >
100100 </ TouchableOpacity >
101+ < TouchableOpacity
102+ style = { styles . button }
103+ onPress = { ( ) => {
104+ this . notif . abandonPermissions ( ) ;
105+ Alert . alert (
106+ 'Abandon Permissions' ,
107+ 'Reload the app to register again with a new token'
108+ ) ;
109+ } } >
110+ < Text > Abandon Permissions</ Text >
111+ </ TouchableOpacity >
101112
102113 < View style = { styles . spacer } > </ View >
103114
Original file line number Diff line number Diff line change @@ -98,4 +98,8 @@ export default class NotifService {
9898 cancelAll ( ) {
9999 PushNotification . cancelAllLocalNotifications ( ) ;
100100 }
101+
102+ abandonPermissions ( ) {
103+ PushNotification . abandonPermissions ( ) ;
104+ }
101105}
Original file line number Diff line number Diff line change @@ -204,6 +204,11 @@ Notifications.localNotificationSchedule = function(details) {
204204 }
205205} ;
206206
207+ /* Abandon Permissions */
208+ Notifications . abandonPermissions = function ( ) {
209+ this . handler . abandonPermissions ( ) ;
210+ }
211+
207212/* Internal Functions */
208213Notifications . _onRegister = function ( token ) {
209214 if ( this . onRegister !== false ) {
@@ -331,10 +336,6 @@ Notifications.popInitialNotification = function(handler) {
331336 } ) ;
332337} ;
333338
334- Notifications . abandonPermissions = function ( ) {
335- return this . callNative ( 'abandonPermissions' , arguments ) ;
336- } ;
337-
338339Notifications . checkPermissions = function ( ) {
339340 return this . callNative ( 'checkPermissions' , arguments ) ;
340341} ;
You can’t perform that action at this time.
0 commit comments