Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jestcastro authored Jul 8, 2017
2 parents 6ae6219 + 213e9c0 commit 42ed87c
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 6 deletions.
13 changes: 10 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:
```
<plugin name="cordova-plugin-firebase" spec="0.1.21" />
<plugin name="cordova-plugin-firebase" spec="0.1.22" />
```
or by running:
```
cordova plugin add [email protected].21 --save
cordova plugin add [email protected].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:

Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 5 additions & 1 deletion plugin.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<plugin id="cordova-plugin-firebase" version="0.1.21"
<plugin id="cordova-plugin-firebase" version="0.1.22"
xmlns="http://apache.org/cordova/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android">
<name>Google Firebase Plugin</name>
Expand Down Expand Up @@ -31,6 +31,9 @@ xmlns:android="http://schemas.android.com/apk/res/android">
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<service android:enabled="true" android:exported="false" android:name="com.google.android.gms.measurement.AppMeasurementService" />
</config-file>
<config-file target="AndroidManifest.xml" parent="/manifest/application">
<service android:name="org.apache.cordova.firebase.FirebasePluginMessagingService">
<intent-filter>
Expand All @@ -49,6 +52,7 @@ xmlns:android="http://schemas.android.com/apk/res/android">
<source-file src="src/android/OnNotificationOpenReceiver.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginInstanceIDService.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/FirebasePluginMessagingService.java" target-dir="src/org/apache/cordova/firebase" />
<source-file src="src/android/colors.xml" target-dir="res/values" />

<framework src="src/android/build.gradle" custom="true" type="gradleReference" />
<framework src="com.google.firebase:firebase-core:+" />
Expand Down
2 changes: 1 addition & 1 deletion scripts/after_prepare.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
21 changes: 21 additions & 0 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Bundle>();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/android/FirebasePluginMessagingService.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ private void sendNotification(String id, String title, String messageBody, Map<S
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setContentTitle(title)
.setContentText(messageBody)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setStyle(new NotificationCompat.BigTextStyle().bigText(messageBody))
.setAutoCancel(true)
.setSound(defaultSoundUri)
Expand Down
6 changes: 6 additions & 0 deletions src/android/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="primary">#FFFFFF00</color>
<color name="primary_dark">#FF220022</color>
<color name="accent">#FF00FFFF</color>
</resources>
1 change: 1 addition & 0 deletions src/ios/FirebasePlugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
15 changes: 15 additions & 0 deletions src/ios/FirebasePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 4 additions & 0 deletions www/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
};
Expand Down

0 comments on commit 42ed87c

Please sign in to comment.