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

Commit 9c26a7b

Browse files
authored
Merge pull request #1425 from GabeConsalter/add-revoke-token-method
Added Abandon Permissions method to Android
2 parents a775d48 + 13325b4 commit 9c26a7b

File tree

6 files changed

+43
-10
lines changed

6 files changed

+43
-10
lines changed

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff 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.

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import com.facebook.react.bridge.ReadableMap;
2626
import com.facebook.react.bridge.WritableMap;
2727

28+
import java.io.IOException;
2829
import java.util.HashMap;
2930
import java.util.Map;
3031
import 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
}

component/index.android.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff 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-
6864
NotificationsComponent.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+
134134
module.exports = {
135135
state: false,
136136
component: new NotificationsComponent()

example/App.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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

example/NotifService.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,8 @@ export default class NotifService {
9898
cancelAll() {
9999
PushNotification.cancelAllLocalNotifications();
100100
}
101+
102+
abandonPermissions() {
103+
PushNotification.abandonPermissions();
104+
}
101105
}

index.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff 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 */
208213
Notifications._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-
338339
Notifications.checkPermissions = function() {
339340
return this.callNative('checkPermissions', arguments);
340341
};

0 commit comments

Comments
 (0)