Skip to content

Commit

Permalink
Merge branch 'master' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
dpa99c committed Aug 15, 2019
2 parents 7cefd34 + f7199fa commit b9eee32
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# Version 6.0.6
* Fix parameter type passed to hasPermission success callback for Android. Fixes [#83](See https://github.com/dpa99c/cordova-plugin-firebasex/issues/83).

# Version 6.0.5
* Fix `hasPermission()` to return boolean result on Android (same as iOS).
* Update docs to flag this as a breaking change from `cordova-plugin-firebase`.
* Resolves [#81](See https://github.com/dpa99c/cordova-plugin-firebasex/issues/81).

# Version 6.0.4
* Replace dependency on `cordova-lib` with `xml2js`.
* (iOS) Restore placeholder GoogleService-Info.plist.
Expand Down
65 changes: 61 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ To help ensure this plugin is kept updated, new features are added and bugfixes
- [Installation](#installation)
- [Supported Cordova Versions](#supported-cordova-versions)
- [Migrating from cordova-plugin-firebase](#migrating-from-cordova-plugin-firebase)
- [Breaking API changes](#breaking-api-changes)
- [Ionic 4](#ionic-4)
- [Ionic 3](#ionic-3)
- [Build environment notes](#build-environment-notes)
- [Specifying dependent library versions](#specifying-dependent-library-versions)
- [PhoneGap Build](#phonegap-build)
Expand Down Expand Up @@ -131,11 +134,64 @@ If you already have [cordova-plugin-firebase](https://github.com/arnesson/cordov
npm install
cordova plugin add cordova-plugin-firebasex
cordova platform add android


#### Breaking API changes
**IMPORTANT:** Recent versions of `cordova-plugin-firebasex` have made breaking changes to the plugin API in order to fix bugs or add more functionality.
Therefore you can no longer directly substitute `cordova-plugin-firebasex` in place of `cordova-plugin-firebase` without making code changes.
Please see the `CHANGELOG.md` for a list of breaking changes and see this plugin's documentation below for current API features.

You should be aware of the following breaking changes compared with `cordova-plugin-firebase`:
* Minimum supported Cordova versions
* `cordova@9` (CLI)
* `cordova-android@8` (Android platform)
* `cordova-ios@5` (iOS platform)
* Migrated to AndroidX from legacy Android Support Library
* add dependency on [cordova-plugin-androidx](https://github.com/dpa99c/cordova-plugin-androidx) and [cordova-plugin-androidx-adapter](https://github.com/dpa99c/cordova-plugin-androidx-adapter)
* Migrated to Cocoapods to satisfy Firebase SDK dependencies on iOS
* `onNotificationOpen()` renamed to `onMessageReceived()`
* `tap` parameter is only set when user taps on a notification (not when a message is received from FCM)
* `tap=foreground|background` instead of `tap=true|false`
* `hasPermission()` receives argument as a boolean (rather than an object with `isEnabled` key)
* e.g. `window.FirebasePlugin.hasPermission(function(hasPermission){
console.log("Permission is " + (hasPermission ? "granted" : "denied"));
});`
* Adds support for foreground notifications and data notification messages

#### Ionic 4
[This PR](https://github.com/ionic-team/ionic-native/pull/3106) adds an [Ionic Native firebase-x Typescript wrapper](https://github.com/ionic-team/ionic-native/blob/master/src/%40ionic-native/plugins/firebase-x/index.ts) for using `cordova-plugin-firebasex` with Ionic 4.
The API is similar to the [Ionic Native Firebase](https://ionicframework.com/docs/native/firebase) wrapper.

ionic cordova plugin add cordova-plugin-firebasex
npm install @ionic-native/firebase-x

import { FirebaseX } from "@ionic-native/firebase-x/ngx";
constructor(private firebase: FirebaseX)
this.firebase.getToken().then(token => console.log(`The token is ${token}`))
this.firebase.onMessageReceived().subscribe(data => console.log(`FCM message: ${data}`));
#### Ionic 3
The above PR does not work for Ionic 3 so you (currently) can't use the [Ionic Native Firebase](https://ionicframework.com/docs/native/firebase) Typescript wrapper with Ionic 3.
(i.e. `import { Firebase } from "@ionic-native/firebase"` will not work).

To use `cordova-plugin-firebasex` with Ionic 3, you'll need to call its Javascript API directly from your Typescript app code, for example:

(<any>window).FirebasePlugin.getToken(token => console.log(`token: ${token}`))

(<any>window).FirebasePlugin.onMessageReceived((message) => {
if (message.tap) { console.log(`Notification was tapped in the ${message.tap}`); }
})

If you want to make the `onMessageReceived()` JS API behave like the Ionic Native wrapper:

onNotificationOpen() {
return new Observable(observer => {
(window as any).FirebasePlugin.onMessageReceived((response) => {
observer.next(response);
});
});
}
...
this.onNotificationOpen().subscribe(data => console.log(`FCM message: ${data}`));

## Build environment notes

Expand Down Expand Up @@ -891,8 +947,9 @@ window.FirebasePlugin.grantPermission(function(hasPermission){
});
```
#### hasPermission
Check permission to receive push notifications and return `hasPermission: true`.
iOS only (Android will always return true).
Check permission to receive push notifications and return the result to a callback function as boolean.
On iOS, returns true is runtime permission for remote notifications is granted and enabled in Settings.
On Android, returns true if remote notifications are enabled.
```
window.FirebasePlugin.hasPermission(function(hasPermission){
console.log("Permission is " + (hasPermission ? "granted" : "denied"));
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/dpa99c/cordova-plugin-firebase"
},
"name": "cordova-plugin-firebasex",
"version": "6.0.4",
"version": "6.0.6",
"description": "Cordova plugin for Google Firebase",
"cordova": {
"id": "cordova-plugin-firebase",
Expand Down
2 changes: 1 addition & 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-firebasex" version="6.0.4"
<plugin id="cordova-plugin-firebasex" version="6.0.6"
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
6 changes: 2 additions & 4 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("setDefaultChannel")) {
this.setDefaultChannel(callbackContext, args.getJSONObject(0));
return true;
} else if (action.equals("hasPermission") || action.equals("grantPermission")) {
} else if (action.equals("grantPermission")) {
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
return true;
}
Expand Down Expand Up @@ -403,9 +403,7 @@ public void run() {
try {
NotificationManagerCompat notificationManagerCompat = NotificationManagerCompat.from(cordovaActivity);
boolean areNotificationsEnabled = notificationManagerCompat.areNotificationsEnabled();
JSONObject object = new JSONObject();
object.put("isEnabled", areNotificationsEnabled);
callbackContext.success(object);
callbackContext.success(areNotificationsEnabled ? 1 : 0);
} catch (Exception e) {
handleExceptionWithContext(e, callbackContext);
}
Expand Down

0 comments on commit b9eee32

Please sign in to comment.