Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Abandon Permissions method to Android #1425

Merged
merged 6 commits into from
May 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
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 @@ -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;
}
}
}
8 changes: 4 additions & 4 deletions component/index.android.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
};
Expand Down Expand Up @@ -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()
Expand Down
11 changes: 11 additions & 0 deletions example/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,17 @@ export default class App extends Component {
}}>
<Text>Request Permissions</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.button}
onPress={() => {
this.notif.abandonPermissions();
Alert.alert(
'Abandon Permissions',
'Reload the app to register again with a new token'
);
}}>
<Text>Abandon Permissions</Text>
</TouchableOpacity>

<View style={styles.spacer}></View>

Expand Down
4 changes: 4 additions & 0 deletions example/NotifService.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,4 +116,8 @@ export default class NotifService {
cancelAll() {
PushNotification.cancelAllLocalNotifications();
}

abandonPermissions() {
PushNotification.abandonPermissions();
}
}
9 changes: 5 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -315,10 +320,6 @@ Notifications.popInitialNotification = function(handler) {
});
};

Notifications.abandonPermissions = function() {
return this.callNative('abandonPermissions', arguments);
};

Notifications.checkPermissions = function() {
return this.callNative('checkPermissions', arguments);
};
Expand Down