diff --git a/README.md b/README.md index 4a28e7e00..3dfd13b56 100644 --- a/README.md +++ b/README.md @@ -3,18 +3,18 @@ This update was done to test phone authentication in iOS. All other methods have # cordova-plugin-firebase This plugin brings push notifications, analytics, event tracking, crash reporting and more from Google Firebase to your Cordova project! -Android and iOS supported (including iOS 10). +Android and iOS supported. ## Installation See npm package for versions - https://www.npmjs.com/package/cordova-plugin-firebase Install the plugin by adding it your project's config.xml: ``` - + ``` or by running: ``` -cordova plugin add cordova-plugin-firebase@0.1.21 --save +cordova plugin add cordova-plugin-firebase@0.1.22 --save ``` Download your Firebase configuration files, GoogleService-Info.plist for ios and google-services.json for android, and place them in the root folder of your cordova project: @@ -192,6 +192,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: diff --git a/package.json b/package.json index b843e1783..5c337857c 100644 --- a/package.json +++ b/package.json @@ -8,7 +8,7 @@ "url": "https://github.com/jestcastro/cordova-plugin-firebase" }, "name": "cordova-plugin-firebase", - "version": "0.1.21", + "version": "0.1.22", "description": "Cordova plugin for Google Firebase", "cordova": { "id": "cordova-plugin-firebase", diff --git a/plugin.xml b/plugin.xml index d92b19d1d..389ffc8f2 100644 --- a/plugin.xml +++ b/plugin.xml @@ -1,5 +1,5 @@ - Google Firebase Plugin @@ -31,6 +31,9 @@ xmlns:android="http://schemas.android.com/apk/res/android"> + + + @@ -49,6 +52,7 @@ xmlns:android="http://schemas.android.com/apk/res/android"> + diff --git a/scripts/after_prepare.js b/scripts/after_prepare.js index ff7ba252c..ed0250bda 100755 --- a/scripts/after_prepare.js +++ b/scripts/after_prepare.js @@ -40,7 +40,7 @@ if (directoryExists("platforms/ios")) { if (fileExists(paths[i])) { try { var contents = fs.readFileSync(paths[i]).toString(); - fs.writeFileSync("platforms/ios/" + name + "/Resources/Resources/GoogleService-Info.plist", contents) + fs.writeFileSync("platforms/ios/" + name + "/Resources/GoogleService-Info.plist", contents) } catch(err) { process.stdout.write(err); } diff --git a/src/android/FirebasePlugin.java b/src/android/FirebasePlugin.java index b391878ef..69499c695 100755 --- a/src/android/FirebasePlugin.java +++ b/src/android/FirebasePlugin.java @@ -63,6 +63,7 @@ protected void pluginInitialize() { public void run() { Log.d(TAG, "Starting Firebase plugin"); mFirebaseAnalytics = FirebaseAnalytics.getInstance(context); + mFirebaseAnalytics.setAnalyticsCollectionEnabled(true); if (extras != null && extras.size() > 1) { if (FirebasePlugin.notificationStack == null) { FirebasePlugin.notificationStack = new ArrayList(); @@ -99,6 +100,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; @@ -355,6 +359,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(); diff --git a/src/android/FirebasePluginMessagingService.java b/src/android/FirebasePluginMessagingService.java index 04b653312..a42ce60e3 100755 --- a/src/android/FirebasePluginMessagingService.java +++ b/src/android/FirebasePluginMessagingService.java @@ -87,6 +87,7 @@ private void sendNotification(String id, String title, String messageBody, Map + + #FFFFFF00 + #FF220022 + #FF00FFFF + \ No newline at end of file diff --git a/src/ios/FirebasePlugin.h b/src/ios/FirebasePlugin.h index 58b4cf603..d84d235ae 100755 --- a/src/ios/FirebasePlugin.h +++ b/src/ios/FirebasePlugin.h @@ -12,6 +12,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; diff --git a/src/ios/FirebasePlugin.m b/src/ios/FirebasePlugin.m index 13e44d8d8..aa4391a32 100644 --- a/src/ios/FirebasePlugin.m +++ b/src/ios/FirebasePlugin.m @@ -177,6 +177,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; diff --git a/www/firebase.js b/www/firebase.js index 1ff8fe7a7..48bf5edc8 100644 --- a/www/firebase.js +++ b/www/firebase.js @@ -43,6 +43,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]); };