Skip to content

Commit

Permalink
Merge pull request arnesson#289 from hardikthakkar3/master
Browse files Browse the repository at this point in the history
Unregister method added.
  • Loading branch information
robertarnesson authored May 30, 2017
2 parents c765744 + ece1e75 commit 7a69b95
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,13 @@ Unsubscribe from a topic:
window.FirebasePlugin.unsubscribe("example");
```

### unregister

Unregister from firebase, used to stop receiving push notifications. Call this when you logout user from your app. :
```
window.FirebasePlugin.unregister();
```

### logEvent

Log an event using Analytics:
Expand Down
20 changes: 20 additions & 0 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("unsubscribe")) {
this.unsubscribe(callbackContext, args.getString(0));
return true;
} else if (action.equals("unregister")) {
this.unregister(callbackContext);
return true;
} else if (action.equals("onNotificationOpen")) {
this.onNotificationOpen(callbackContext);
return true;
Expand Down Expand Up @@ -340,6 +343,23 @@ public void run() {
});
}

private void unregister(final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
FirebaseInstanceId.getInstance().deleteInstanceId();
String currentToken = FirebaseInstanceId.getInstance().getToken();
if (currentToken != null) {
FirebasePlugin.sendToken(currentToken);
}
callbackContext.success();
} catch (Exception e) {
callbackContext.error(e.getMessage());
}
}
});
}

private void logEvent(final CallbackContext callbackContext, final String name, final JSONObject params) throws JSONException {
final Bundle bundle = new Bundle();
Iterator iter = params.keys();
Expand Down
1 change: 1 addition & 0 deletions src/ios/FirebasePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- (void)getBadgeNumber:(CDVInvokedUrlCommand*)command;
- (void)subscribe:(CDVInvokedUrlCommand*)command;
- (void)unsubscribe:(CDVInvokedUrlCommand*)command;
- (void)unregister:(CDVInvokedUrlCommand*)command;
- (void)onNotificationOpen:(CDVInvokedUrlCommand*)command;
- (void)onTokenRefresh:(CDVInvokedUrlCommand*)command;
- (void)sendNotification:(NSDictionary*)userInfo;
Expand Down
15 changes: 15 additions & 0 deletions src/ios/FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,21 @@ - (void)unsubscribe:(CDVInvokedUrlCommand *)command {
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}

- (void)unregister:(CDVInvokedUrlCommand *)command {
[[FIRInstanceID instanceID] deleteIDWithHandler:^void(NSError *_Nullable error){
if (error) {
NSLog(@"Unable to delete instance");
} else {
NSString* currentToken = [[FIRInstanceID instanceID] token];
if (currentToken != nil) {
[self sendToken:currentToken];
}
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
}];
}

- (void)onNotificationOpen:(CDVInvokedUrlCommand *)command {
self.notificationCallbackId = command.callbackId;

Expand Down
4 changes: 4 additions & 0 deletions www/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ exports.unsubscribe = function(topic, success, error) {
exec(success, error, "FirebasePlugin", "unsubscribe", [topic]);
};

exports.unregister = function(success, error) {
exec(success, error, "FirebasePlugin", "unregister", []);
};

exports.logEvent = function(name, params, success, error) {
exec(success, error, "FirebasePlugin", "logEvent", [name, params]);
};
Expand Down

0 comments on commit 7a69b95

Please sign in to comment.