Phonegap Push Plugin 2.0.0 released

Many here are probably using push notifications in their apps, and most of them are probably using phonegap-plugin-push for it. There was just a big 2.0.0 release:

This means the plugin finally supports FCM instead of GCM.

Any first experiences?

1 Like

So I’m on it. Took me two hours of preparation for the migration (could document it later if at the end everything is working).

Right now, I tried to build my app and I face following error while building android:

Gradle dependencies are the worst…

Somewhere I remember that I already faced that problem this year with a plugin where a decency was set as + where it should specify an explicit version…try to remember which and find the issue in github to link it

Update: Found it https://github.com/jeduan/cordova-plugin-facebook4/issues/507

Found a workaround, classic gradle conflict because a plugin doesn’t set explicitly the library version. I documented it in the issue:

I gonna continue the migration and will document at the end

Update: Android and iOS are compiling/building with success. Don’t have my phone with, will test tomorrow

1 Like

Just successfully tested on my (real) iPhone6 and Samsung Edge, Push notifications plugin version 2.0.0 looks good to me.

Here my migration guide for phonegap-plugin-push 1.10.5 to 2.0.0:

1_Configuration files

With the version 2.0.0 of the plugin you will not set anymore the SENDER_ID during the installation of the plugin respectively set it in your config.xml.

Instead of that you have to generate configuration files, respectively google-services.json for Android and GoogleService-Info.plist for iOS, in your Firebase account.

To do so, you could follow following documentation:

https://support.google.com/firebase/answer/7015592

2_Add configuration files to your project

Ultimately the two new above configuration files should be placed in the root folder of the platforms, respectively under platforms/android/google-services.json and platforms/ios/GoogleService-Info.plist.

Since sometimes we remove and add the platform again, it won’t be good to just copy them there manually. Therefore I suggest to save them under following folder and to add a cordova hook to automatically copy them at build time.

Copy your config files into:

./resources/android/google-services.json
./resources/ios/GoogleService-Info.plist

3_Cordova hook to copy/deploy configuration files

First of all, if you don’t have it yet, you will need to install the ncp library

npm install ncp --save-dev

Then add the following two scripts. I saved them under a folder ./scripts, of course this could be modified.

./scripts/cordova-android-prepare.js:

var ncp = require('ncp').ncp;

var SRC_FILE = 'resources/android/google-services.json';
var DEST_FILE = 'platforms/android/google-services.json';

module.exports = function (context) {

    ncp(SRC_FILE, DEST_FILE, function (err) {
        if (err) {
            return console.error(err);
        } else {
            console.log('done!');
        }
    });
};

./scripts/cordova-ios-prepare.js:

var ncp = require('ncp').ncp;

var SRC_FILE = 'resources/ios/GoogleService-Info.plist';
var DEST_FILE = 'platforms/ios/GoogleService-Info.plist';

module.exports = function (context) {

    ncp(SRC_FILE, DEST_FILE, function (err) {
        if (err) {
            return console.error(err);
        } else {
            console.log('done!');
        }
    });
};

Note: With ncp, when you are copying a single file, you have to set the filename in the destination file and not just set a destination directory, just saying that because I have lost a couple of minutes there :wink:

Good, now that we have the scripts, we need to set the cordova hooks in the config.xml like following:

<platform name="android">
    <hook src="scripts/cordova-android-prepare.js" type="after_prepare" />
</platform>
<platform name="ios">
    <hook src="scripts/cordova-ios-prepare.js" type="after_prepare" />
</platform>

Note: after_prepare is maybe not the best lifecycle hook because the files gonna be copied each time you gonna build, maybe would have been better on plugin installation time or while adding the platform. But well I don’t mind

4_Update Cocoapods

Not sure if Cocoapods really need to be updated be I thought, better do it. Also I did a (re)installation and update.

gem install cocoapods
pod setup

Note: If you previously installed Cocoapods with sudo then use sudo again for your sudo gem install cocoa pods. pod setup always without sudo.

4_Install phonegap-plugin-push 2.0.0

ionic cordova plugin rm phonegap-plugin-push
ionic cordova plugin add phonegap-plugin-push

5_(Optional I guess) Remove and add your platform again

Once I faced problem while updating phonegap-plugin-push which I resolved by removing and adding my platforms again. Therefore, since that date, I always do it now (but only when it goes to this plugin).

ionic cordova platform rm ios
ionic cordova platform add ios
ionic cordova platform rm android
ionic cordova platform add android

Important: Don’t forget, if you would had modified something manually in Xcode for configuration purpose, just don’t forget to process the same modifications manually again in Xcode after having added the platform again

5_Build iOS

Building iOS was straight forward for me, no problem noticed.

ionic cordova build ios --prod

6_(Possible conflict) Build android

While build android I faced a gradle conflict like stated above in this post. If you use the cordova-plugin-google-analytics you might face the same issue. Have a look in the following issue to find the solution (look for my post @peterpeterparker)

Except that, build went smoothly

ionic cordova build android --prod

7_Tests

That’s it, test the new plugin on real devices

Note: Don’t know if removing and adding the platform again was the reason or update ionic-app-script or if the new phonegap-plugin-push is lighter, but after this all process I noticed that my debug apk size just dropped of 1.4mb (previously 7.5mb, now 6.1mb) :thumbsup:

4 Likes