1

I've seen a lot of tutorials and forum posts about using Push notifications with Phonegap, but most of these seem out of date. Does anybody know whether this works today (2019)?

I created the Push Notification demo through Phonegap and ran it on my Android 8 device. While it runs and says "Registered", there is no sample notification.

I tried sending a push via the CLI and that didn't work either (I have been told this was removed so will no longer work, despite Adobe's out of date tutorial page)

(note the Phonegap Developer app says it isnt compatible with Android 8 on the Play Store so had to download the APK from elsewhere. Was that a sign that nothing would work?)

Then I found that there was a "new" push service for Phonegap, which I also downloaded, only to find out that this is no longer in service either.

So NOW I find that there are some 3rd party apps which can provide push services (mostly not free). Services such as "PushWhoose".

Does anybody know, do these 3rd party services work? Which are the most reliable ones to use? And on what versions of Android and iOS do they work?

Any help appreciated.

Delmontee
  • 1,898
  • 2
  • 26
  • 44

1 Answers1

3

I have many phonegap (CLI-8.0.0) applications in production that are currently receiving notifications in 2019 so yes it's work.

I used the 3rd party Cloud messaging by Firebase (https://firebase.google.com/docs/cloud-messaging/) and the phonegap-plugin-push (version 2.1.3 for Android and last version for iOS)

We have tested the following on Android 7 and 8 and iOS 12.

Notifications were sent with the C# Firebase API.

How to use Firebase with Phonegap :

First you have to install 4 plugin for Android :

<plugin name="phonegap-plugin-push" spec="2.1.3" />
<plugin name="cordova-android-support-gradle-release" spec="https://github.com/dpa99c/cordova-android-support-gradle-release.git" />
<plugin name="cordova-android-play-services-gradle-release" spec="https://github.com/dpa99c/cordova-android-play-services-gradle-release.git" />
<plugin name="cordova-android-firebase-gradle-release" spec="https://github.com/dpa99c/cordova-android-firebase-gradle-release.git" />

I used 2.1.3 version of plugin for android because the last version didn't work for me.

*-gradle-release grants you full compatibility between phonegap-plugin-push and other plugins because there are often conflicts

For iOS i used last version :

<plugin name="phonegap-plugin-push" />

After that, you have to register your apps to firebase until you have sender id and google-services.json.

For apple you have to grant your certificate the push notification rights and get an APNS certificate.

When you have your sender id, google-services.json and GoogleService-Info.plist you just have to configure your config.xml like this:

<platform name="android" custom="push">
    <plugin name="cordova-android-support-gradle-release" spec="https://github.com/dpa99c/cordova-android-support-gradle-release.git" />
    <plugin name="phonegap-plugin-push" spec="2.1.3">
        <param name="SENDER_ID" value="XXXXXXXXXXXXXXXXXXXXXX" />
    </plugin>
    <plugin name="cordova-android-play-services-gradle-release" spec="https://github.com/dpa99c/cordova-android-play-services-gradle-release.git" />
    <plugin name="cordova-android-firebase-gradle-release" spec="https://github.com/dpa99c/cordova-android-firebase-gradle-release.git"/>
    <resource-file src="google-services.json" target="/app/google-services.json" />
</platform>

<platform name="ios" custom="push">
    <plugin name="phonegap-plugin-push">
        <param name="SENDER_ID" value="XXXXXXXXXXXXXXXX" />
    </plugin>
    <resource-file src="GoogleService-Info.plist" />
</platform>

google-services.json and GoogleService-Info.plist has to be at the same level of your config.xml in the www folder.

After that, the documentation of the plugin will be able to help you better than me.

Imran NZ
  • 1,327
  • 2
  • 12
  • 22
Enzo B.
  • 2,341
  • 1
  • 11
  • 33
  • Thanks for the reply. Is there any way of sending a test message directly from the CLI rather than having to use a 3rd party? – Delmontee Mar 07 '19 at 16:05
  • I never do it but i found this : http://docs.phonegap.com/references/phonegap-cli/push/ I think there are prerequisites to configure the application as a receiver of this type of notification but I didn't find any information on it. I hope this will help you – Enzo B. Mar 07 '19 at 16:17
  • Thanks. I tried that one the other day but it is no longer supported in the phonegap CLI. Annoying they don't remove out of date content. Regarding the Firebase cloud messgaing service, are there any other dependencies to be added other than what comes with Phonegap by default + the FCM plugin? Sorry for all the questions – Delmontee Mar 08 '19 at 07:31
  • Don't apologize, I won't be on stackoverflow if I don't want to answer your questions. I edited my answer. – Enzo B. Mar 08 '19 at 08:42
  • This is great, many thanks! I read that sender ID is no longer required, but will try the above . – Delmontee Mar 08 '19 at 09:07
  • I installed the Phonegap test push notification project, installed all 4 plugins, signed up to Firebase, downloaded the google-services.json file and placed in the correct folder. I've added the necessary code to the config.xml and the sender ID. I've set up a push notification to come through when the app is launched. I run the app through the Phonegap Developer app and it shows "Registered" but no message comes through. The browser version has a js error "uncaught Error: Service Workers are not supported on your browser. at new PushNotification)", and also no message comes through :(. – Delmontee Mar 13 '19 at 08:25
  • Are you still testing under iOS? Cause Service Worker don't work on Safari Webkit actually (https://developer.mozilla.org/fr/docs/Web/API/Service_Worker_API#Compatibilit%C3%A9_des_navigateurs) – Enzo B. Mar 13 '19 at 09:13
  • I think you'd better open a new post to reach more people and better explain your new problem. – Enzo B. Mar 13 '19 at 09:41
  • 1
    Added here: https://stackoverflow.com/questions/55139616/adobe-phonegap-push-notifications-with-firebase-cloud-on-android-2019-question – Delmontee Mar 13 '19 at 10:29