- Introduce new variable for iOS
IOS_GOOGLE_UTILITIES_VERSION
to update pod version ofGoogleUtilities
. Default to7.11.5
.
- Remove post install script (for installing ionic native dependencies) causing issue with recent Node.js versions
- Support Android SDK level 33 (Android 13): user permission is now required to start receiving push notifications from Android 13+. Calling
FCM.requestPushPermission()
will now display a push permission dialog in Android 13 or above.
- Support Android SDK level 31 (Android 12)
- IOS_FIREBASE_MESSAGING_VERSION upgraded to 7.4.0;
- FCM.hasPermission now supports Android;
- On iOS, getToken will now wait until fcm token is defined to return it;
- FCM.getInitialPushPayload now uses UTF8 instead of ISOLatin;
Downgraded Cordova and Cordova-Android minimal required versions.
Fixed auto install of ionic-specific dependencies on Windows
Added IOS_FIREBASE_MESSAGING_VERSION plugin variable to force a fixed Firebase/Messaging pod version.
For pure Cordova projects, ionic dependencies are skipped for "ionic", "ionic/ngx" and "ionic/v4".
Upgraded Android and Node depenencies.
Android: Avoided setting initialPushPayload from a non-tapped notification.
Removed optional Firebase/Analytics iOS dependency.
Added deleteInstanceId to allow user's "resetting" Firebase session (https://firebase.google.com/support/privacy/manage-iids#delete_an_instance_id).
iOS: Values sent as notification on push payload should never overwrite values sent as data.
Android: tapping action small refactor.
Ionic: Removed tslib dependency due to reported incompatibility.
For iOS: Added title
, subtitle
, body
and badge
to the data given to JS.
This data is coming from notification part of the push payload, instead of only from data.
Android has been responding this way for a long time with title
and body
.
Defined minimal version of "cordova" package supported as version 9. Due to issues of supporting lower versions and "cordova-ios@5+" without deprecated configuration.
Removed explicit definition of "Firebase/Analytics" and "Firebase/Messaging" due to lack of matching “>=” definitions between plugins.
getInitialPushPayload: Conversion of NSData* into NSDictonary* fix -- Thanks to @medeirosrafael for debugging and fixing it!
Avoided execution of install_ionic_dependencies.bat after the app is installed;
Removed old framework dependencies -- Thanks for @QuentinFarizon, for pointing it out!
Removed auto-cdnfy due to service issues;
Set AndroidXEnabled for cordova-android-9.0.0 (https://cordova.apache.org/announcements/2020/06/29/cordova-android-9.0.0.html).
Simplified ionic/ngx/FCM.d.ts imports
Renamed extension scripts/install_ionic_dependencies.sh to .bat, to have it running on windows.
Simplified ionic/FCM.js and ionic/ngx/FCM.js files to ease building with them.
Improved scripts/install_ionic_dependencies.sh windows support.
Simplified ionic/v4/FCM.js file by setting the FCM function in the global context.
Simplified .d.ts files by removing the new "type" from imports and exports.
Replaced native to JS context messaging, from JS injection to event subscription.
Breaking update released. Please pay atention to the changes in plugin preferences and API methods.
The FCMPlugin.requestPushPermissionIOS
function now, not only triggers the request alert, but also returns, as boolean, if the permission was given.
FCMPlugin.requestPushPermissionIOS(
function(wasPermissionGiven) {
console.info("Was permission given: "+wasPermissionGiven);
},
function(error) {
console.error(error);
},
ios9Support: {
timeout: 10, // How long it will wait for a decision from the user before returning `false`
interval: 0.3 // How long between each permission verification
}
);
Note: On iOS 9, there is no way to know if the user has denied the permissions or he has not yet decided. For this reason, specifically for iOS 9, after presenting the alert, a timed loop waits until it knows that the user has either given the permissions or that the time has expired. On iOS 10+, the return is given as soon as the user has selected, ignoring these options.
FCMPlugin.createNotificationChannelAndroid improved, now accepting three other options: "sound", "lights" and "vibration", like in:
FCMPlugin.createNotificationChannelAndroid({
id: "urgent_alert", // required
name: "Urgent Alert", // required
description: "Very urgent message alert",
importance: "high", // https://developer.android.com/guide/topics/ui/notifiers/notifications#importance
visibility: "public", // https://developer.android.com/training/notify-user/build-notification#lockscreenNotification
sound: "alert_sound", // In the "alert_sound" example, the file should located as resources/raw/alert_sound.mp3
lights: true, // enable lights for notifications
vibration: true // enable vibration for notifications
});
IOS 9 support reintroduced.
For Android, some notification properties are only defined programmatically, one of those is channel. Channel can define the default behavior for notifications on Android 8.0+. This feature was meant to bring the channel-only configurations importance and visibility:
FCMPlugin.createNotificationChannelAndroid({
id: "urgent_alert", // required
name: "Urgent Alert", // required
description: "Very urgent message alert",
importance: "high", // https://developer.android.com/guide/topics/ui/notifiers/notifications#importance
visibility: "public", // https://developer.android.com/training/notify-user/build-notification#lockscreenNotification
});
To have a notification to use the channel, you have to add to the push notification payload the key android_channel_id
with the id given to createNotificationChannelAndroid
(https://firebase.google.com/docs/cloud-messaging/http-server-ref#notification-payload-support)
As a hotfix to avoid incompatibility with cordova-plugin-ionic-webview, the the changes requested for cordova support (https://cordova.apache.org/howto/2020/03/18/wkwebviewonly) will not be automatic applied.
On iOS, first run doesn't automatically request Push permission.
The permission, as it is still required, may now be requested from javascript at any moment by executing:
//FCMPlugin.requestPushPermissionIOS( successCallback(), errorCallback(err) );
FCMPlugin.requestPushPermissionIOS();
Minor changes omitted.
Replaced UIWebView
with WKWebView
, as required by Apple (https://developer.apple.com/documentation/uikit/uiwebview).
For a smooth upgrade, the changes requested for cordova support (https://cordova.apache.org/howto/2020/03/18/wkwebviewonly) are applied automatically.
For both platforms:
- Not only copies, from application root, the Google Services configuration files on build, but also on install;
onFirebaseDataNotificationIOS
removed, as relied on upstream socket connection, which will is deprecated and will be removed in Firebase 7 (https://firebase.google.com/support/release-notes/ios#fcm, announced in February 25, 2020).
For iOS:
- On install "Remote Notification" is set as a "Background Mode" capacity automatically;
- Firebase now is handled manually, due to complications of auto-swizzling;
- Firebase dependencies are now set to 6.21.0;
- Delayed Firebase registration, by 300ms, to avoid deadlock issue with Watchdog;
- Removed support for iOS 9.
For Android:
- Demonstrative code, for custom notifications, was removed and its imports of androidx classes to improve compatibility with older cordova plugins.
Minor changes omitted.
For the IOS, if app is on the foreground and the app receives a data
push notification, the data can be retrieved by setting the callback to the new method: FCMPlugin.onFirebaseDataNotificationIOS
[Deprecated].
FCMPlugin.onFirebaseDataNotificationIOS(
function(payload) {
console.info("Message id: "+payload.messageID)
console.info("Data parameters: "+payload.appData)
}
);
This method is specifically implemented on IOS due to specific payload format (src/FCMPlugin.d.ts).
Due to a bug introduced in v4.4.3, the file platforms/android/app/src/main/res/values/strings.xml
had two tags included on install, tags which, on build, are also included by [email protected]. Hence failing the build process.
To apply the fix, install the new version and remove these two tags from your values/strings.xml:
<string name="google_app_id">...</string>
<string name="google_api_key">...</string>
ANDROID_DEFAULT_NOTIFICATION_ICON
included as a variable.
To define the default icon for notifications (com.google.firebase.messaging.default_notification_icon
), install this plugin like:
cordova plugin add cordova-plugin-fcm-with-dependecy-updated --variable ANDROID_DEFAULT_NOTIFICATION_ICON="@mipmap/notification_icon"
Older notifications can be cleared from notification center. Works on both IOS and Android.
//FCMPlugin.clearAllNotifications( successCallback(msg), errorCallback(err) );
FCMPlugin.clearAllNotifications();
The old FCMPlugin.getToken
is focused on retrieving the FCM Token.
For the IOS, APNS token can now be retrieved by the new method:
FCMPlugin.getAPNSToken(
function(token) {
console.info("Retrieved token: "+token)
},
function(error) {
console.error(error);
}
);
On android, it will always return null
.
The APNS token, once given, should not change for the same user (as commented on in https://stackoverflow.com/questions/6652242/does-the-apns-device-token-ever-change-once-created).
Although, contrary to APNS, the FCM tokens do expire, and for this reason, FCMPlugin.onTokenRefresh
will be called with the new one FCM token.
Minor changes omitted.
Useful for IOS. On android, it will always return true
.
FCMPlugin.hasPermission(function(doesIt){
// doesIt === true => yes, push was allowed
// doesIt === false => nope, push will not be available
// doesIt === null => still not answered, recommended checking again later
if(doesIt) {
haveFun();
}
});
Minor changes omitted.
- Tested on Android and iOS using Cordova cli 6.4.0, Cordova android 6.0.0 and Cordova ios 4.3.1
- Available sdk functions: onTokenRefresh, getToken, subscribeToTopic, unsubscribeFromTopic and onNotification
- 'google-services.json' and 'GoogleService-Info.plist' are added automatically from Cordova project root to platform folders
- Added data payload parameter to check whether the user tapped on the notification or was received while in foreground.
- Free testing server available for free! https://cordova-plugin-fcm.appspot.com