Skip to content

Commit

Permalink
feat(push-notifications): add unregister functions (#1498)
Browse files Browse the repository at this point in the history
* feat(push-notifications): add unregister functions

* Add to `definitions.ts` and `README.md`

* Update "since" to 5.0.0

* move `call.resolve`
  • Loading branch information
markemer committed Mar 24, 2023
1 parent 999a2a6 commit 878e295
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 0 deletions.
16 changes: 16 additions & 0 deletions push-notifications/README.md
Expand Up @@ -159,6 +159,7 @@ const getDeliveredNotifications = async () => {
<docgen-index>

* [`register()`](#register)
* [`unregister()`](#unregister)
* [`getDeliveredNotifications()`](#getdeliverednotifications)
* [`removeDeliveredNotifications(...)`](#removedeliverednotifications)
* [`removeAllDeliveredNotifications()`](#removealldeliverednotifications)
Expand Down Expand Up @@ -197,6 +198,21 @@ notification permissions, use `requestPermissions()` first.
--------------------


### unregister()

```typescript
unregister() => Promise<void>
```

Unregister the app from push notifications.

This will delete a firebase token on Android, and unregister APNS on iOS.

**Since:** 5.0.0

--------------------


### getDeliveredNotifications()

```typescript
Expand Down
Expand Up @@ -117,6 +117,13 @@ public void register(PluginCall call) {
call.resolve();
}

@PluginMethod
public void unregister(PluginCall call) {
FirebaseMessaging.getInstance().setAutoInitEnabled(false);
FirebaseMessaging.getInstance().deleteToken();
call.resolve();
}

@PluginMethod
public void getDeliveredNotifications(PluginCall call) {
JSArray notifications = new JSArray();
Expand Down
1 change: 1 addition & 0 deletions push-notifications/ios/Plugin/PushNotificationsPlugin.m
Expand Up @@ -5,6 +5,7 @@
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
CAP_PLUGIN(PushNotificationsPlugin, "PushNotifications",
CAP_PLUGIN_METHOD(register, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(unregister, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(checkPermissions, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(requestPermissions, CAPPluginReturnPromise);
CAP_PLUGIN_METHOD(getDeliveredNotifications, CAPPluginReturnPromise);
Expand Down
10 changes: 10 additions & 0 deletions push-notifications/ios/Plugin/PushNotificationsPlugin.swift
Expand Up @@ -47,6 +47,16 @@ public class PushNotificationsPlugin: CAPPlugin {
call.resolve()
}

/**
* Unregister for remote notifications
*/
@objc func unregister(_ call: CAPPluginCall) {
DispatchQueue.main.async {
UIApplication.shared.unregisterForRemoteNotifications()
call.resolve()
}
}

/**
* Request notification permission
*/
Expand Down
9 changes: 9 additions & 0 deletions push-notifications/src/definitions.ts
Expand Up @@ -40,6 +40,15 @@ export interface PushNotificationsPlugin {
*/
register(): Promise<void>;

/**
* Unregister the app from push notifications.
*
* This will delete a firebase token on Android, and unregister APNS on iOS.
*
* @since 5.0.0
*/
unregister(): Promise<void>;

/**
* Get a list of notifications that are visible on the notifications screen.
*
Expand Down

0 comments on commit 878e295

Please sign in to comment.