andrehtissot / cordova-plugin-fcm-with-dependecy-updated

Google FCM Push Notifications Cordova Plugin
MIT License
210 stars 273 forks source link

With version 7.3.1, the onNotification event is not fired in ionic/ngx 4 #171

Open ghost opened 3 years ago

ghost commented 3 years ago

First of all my thanks for this great plugin.

I was updating the plugin in my application to version 7.3.1, and with this change the onNotification event is not being executed in my application.

The saddest thing now, not even going back to the previous version of the plugin which was version 6.4.3, it didn't work anymore.

I get to get the token in my application, and when I send the notification from my nodejs server with the following format:

  data: {
    params: '{"chs_number": 428, "chs_sala_id": null, "chs_sala_last_date": null, "members": [{"per_code": 198, "per_name": "Belen Lopez", "
    silence: '0',
    a_8: 'New video call',
    m_8: 'A user wants to talk to you'
  },
  token: 'dzuyGD2KRICjq48fkzBhGr: APA91bHUX3MlDB9QiSB_8TtZNOLin5gdRSRqAiDTC-MSkFba4XvhvdvMKmVM1jkCvgb6bOrjSnu2nOZuUw9DB4E $
  options: {priority: 'high', timeToLive: 3600}
}

I get a response from the sendToDevice method like the following:

{[
  results: [{messageId: '0: 1599659106658536% 8b3dbe6af9fd7ecd'}],
  canonicalRegistrationTokenCount: 0,
  failureCount: 0,
  successCount: 1,
  multicastId: 1621353511633733600
}
[{messageId: '0: 1599659106658536% 8b3dbe6af9fd7ecd'}]

Which makes me understand that everything is fine on the server side, which is logical since I have not touched anything.

I did a little test by switching to another plugin offered by ionic

Ionic Firebase-messaging and only by changing the interfaces, to said plugin, the onNotification was launched normally, which makes me understand that there is no problem in the APP logic or in the server.

On the server I use the firebase-admin version "firebase-admin": "^ 9.1.0",

and then I expose my package.json of the APP.

{
  "name": "myapp",
  "version": "1.9.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build --configuration=production",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "~8.1.2",
    "@angular/cdk": "~8.2.3",
    "@angular/common": "~8.1.2",
    "@angular/core": "~8.1.2",
    "@angular/fire": "^6.0.0",
    "@angular/forms": "~8.1.2",
    "@angular/material": "^8.2.3",
    "@angular/platform-browser": "~8.1.2",
    "@angular/platform-browser-dynamic": "~8.1.2",
    "@angular/pwa": "^0.900.7",
    "@angular/router": "~8.1.2",
    "@angular/service-worker": "~8.1.2",
    "@ionic-native/android-permissions": "^5.24.0",
    "@ionic-native/app-center-crashes": "^5.23.0",
    "@ionic-native/app-launcher": "^5.23.0",
    "@ionic-native/app-minimize": "^5.23.0",
    "@ionic-native/autostart": "^5.25.0",
    "@ionic-native/background-mode": "^5.25.0",
    "@ionic-native/barcode-scanner": "^5.24.0",
    "@ionic-native/base64": "^5.24.0",
    "@ionic-native/broadcaster": "^5.23.0",
    "@ionic-native/call-number": "^5.26.0",
    "@ionic-native/camera": "^5.23.0",
    "@ionic-native/core": "^5.0.0",
    "@ionic-native/device": "^5.23.0",
    "@ionic-native/facebook": "^5.28.0",
    "@ionic-native/file": "^5.23.0",
    "@ionic-native/file-opener": "^5.26.0",
    "@ionic-native/file-path": "^5.23.0",
    "@ionic-native/file-transfer": "^5.26.0",
    "@ionic-native/firebase-dynamic-links": "^5.27.0",
    "@ionic-native/firebase-messaging": "^5.28.0",
    "@ionic-native/geolocation": "^5.23.0",
    "@ionic-native/in-app-browser": "^5.26.0",
    "@ionic-native/insomnia": "^5.28.0",
    "@ionic-native/ionic-webview": "^5.22.0-beta-1",
    "@ionic-native/local-notifications": "^5.0.0",
    "@ionic-native/sim": "^5.23.0",
    "@ionic-native/social-sharing": "^5.23.0",
    "@ionic-native/splash-screen": "^5.23.0",
    "@ionic-native/status-bar": "^5.23.0",
    "@ionic/angular": "^4.11.10",
    "@ionic/storage": "^2.2.0",
    "@ngx-translate/core": "^11.0.1",
    "@ngx-translate/http-loader": "^4.0.0",
    "@scaffold-digital/ionic-hardware-buttons": "^1.1.0",
    "call-number": "^1.0.1",
    "com-badrit-base64": "^0.2.0",
    "cordova-android": "^8.1.0",
    "cordova-custom-config": "^5.1.0",
    "cordova-install-referrer": "^0.1.5",
    "cordova-plugin-android-permissions": "^1.0.2",
    "cordova-plugin-androidx": "^1.0.2",
    "cordova-plugin-androidx-adapter": "^1.1.0",
    "cordova-plugin-app-launcher": "^0.4.0",
    "cordova-plugin-appminimize": "^1.0.1",
    "cordova-plugin-autostart": "^2.3.0",
    "cordova-plugin-background-mode": "^0.7.3",
    "cordova-plugin-badge": "^0.8.8",
    "cordova-plugin-broadcaster": "^4.1.0",
    "cordova-plugin-camera": "^4.1.0",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-facebook4": "^6.4.0",
    "cordova-plugin-fcm-with-dependecy-updated": "^7.3.1",
    "cordova-plugin-file": "^6.0.2",
    "cordova-plugin-file-opener2": "^3.0.1",
    "cordova-plugin-file-transfer": "^1.7.1",
    "cordova-plugin-filepath": "^1.5.8",
    "cordova-plugin-firebase-analytics": "^4.3.0",
    "cordova-plugin-firebase-dynamiclinks": "^4.4.0",
    "cordova-plugin-firebase-messaging": "^4.4.1",
    "cordova-plugin-geolocation": "^4.0.2",
    "cordova-plugin-inappbrowser": "^4.0.0",
    "cordova-plugin-insomnia": "^4.3.0",
    "cordova-plugin-ionic": "^5.4.7",
    "cordova-plugin-ionic-webview": "^5.0.0",
    "cordova-plugin-local-notification": "^0.9.0-beta.3",
    "cordova-plugin-qrcodejs": "^1.0.0",
    "cordova-plugin-sim": "^1.3.3",
    "cordova-plugin-x-socialsharing": "^5.6.4",
    "cordova-res": "^0.14.0",
    "cordova-sqlite-storage": "^4.0.0",
    "cordova-support-android-plugin": "^1.0.2",
    "cordova-support-google-services": "^1.4.1",
    "core-js": "^2.5.4",
    "cropperjs": "^1.5.7",
    "es6-promise-plugin": "^4.2.2",
    "firebase": "^7.14.5",
    "hammerjs": "^2.0.8",
    "ionic-tooltips": "^4.0.0-beta.0",
    "ionic2-calendar": "^0.5.3",
    "ionic4-star-rating": "^1.1.1",
    "moment": "^2.25.3",
    "mx.ferreyra.callnumber": "0.0.2",
    "ng-pick-datetime": "^7.0.0",
    "ngx-socket-io": "^3.0.1",
    "promise-polyfill": "^8.1.3",
    "rxjs": "^6.5.5",
    "rxjs-compat": "^6.5.5",
    "tslib": "^1.11.1",
    "webrtc-adapter": "^7.5.1",
    "xml-js": "^1.6.11",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/architect": "~0.801.2",
    "@angular-devkit/build-angular": "~0.803.25",
    "@angular-devkit/core": "~8.1.2",
    "@angular-devkit/schematics": "~8.1.2",
    "@angular/cli": "~8.1.2",
    "@angular/compiler": "~8.1.2",
    "@angular/compiler-cli": "~8.1.2",
    "@angular/language-service": "~8.1.2",
    "@ionic/angular-toolkit": "^2.2.0",
    "@types/jasmine": "~3.3.8",
    "@types/jasminewd2": "~2.0.3",
    "@types/node": "~8.9.4",
    "codelyzer": "^5.2.2",
    "cordova-plugin-ionic-keyboard": "^2.2.0",
    "cordova-plugin-splashscreen": "^5.0.3",
    "cordova-plugin-statusbar": "^2.4.3",
    "cordova-plugin-whitelist": "^1.3.4",
    "jasmine-core": "~3.4.0",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.1.0",
    "karma-chrome-launcher": "~2.2.0",
    "karma-coverage-istanbul-reporter": "~2.0.1",
    "karma-jasmine": "~2.0.1",
    "karma-jasmine-html-reporter": "^1.5.3",
    "protractor": "^5.4.3",
    "ts-node": "~7.0.0",
    "tslint": "~5.15.0",
    "typescript": "~3.4.3"
  },
  "description": "An Ionic project",
  "cordova": {
    "plugins": {
      "cordova-sqlite-storage": {},
      "cordova-plugin-geolocation": {},
      "cordova-plugin-device": {},
      "cordova-plugin-file": {},
      "cordova-plugin-ionic-webview": {
        "ANDROID_SUPPORT_ANNOTATIONS_VERSION": "27.+"
      },
      "cordova-plugin-filepath": {},
      "cordova-plugin-whitelist": {},
      "cordova-plugin-statusbar": {},
      "cordova-plugin-splashscreen": {},
      "cordova-plugin-ionic-keyboard": {},
      "cordova-plugin-local-notification": {},
      "cordova-plugin-sim": {},
      "cordova-plugin-appminimize": {},
      "cordova-plugin-broadcaster": {},
      "cordova-custom-config": {},
      "cordova-plugin-x-socialsharing": {
        "ANDROID_SUPPORT_V4_VERSION": "24.1.1+"
      },
      "cordova-plugin-app-launcher": {},
      "cordova-plugin-androidx": {},
      "cordova-plugin-camera": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      },
      "cordova-plugin-androidx-adapter": {},
      "cordova-plugin-android-permissions": {},
      "cordova-plugin-ionic": {
        "APP_ID": "aa78df67",
        "CHANNEL_NAME": "Production",
        "UPDATE_METHOD": "auto",
        "MAX_STORE": "2",
        "MIN_BACKGROUND_DURATION": "30",
        "UPDATE_API": "https://api.ionicjs.com"
      },
      "cordova-plugin-qrcodejs": {},
      "cordova-plugin-background-mode": {},
      "cordova-install-referrer": {},
      "com-badrit-base64": {},
      "cordova-plugin-autostart": {},
      "cordova-plugin-file-opener2": {
        "ANDROID_SUPPORT_V4_VERSION": "27.+"
      },
      "cordova-plugin-file-transfer": {},
      "cordova-plugin-firebase-dynamiclinks": {
        "PAGE_LINK_DOMAIN": "precisapp.page.link",
        "FIREBASE_DYNAMIC_LINKS_VERSION": "19.1.+"
      },
      "mx.ferreyra.callnumber": {},
      "cordova-plugin-inappbrowser": {},
      "call-number": {},
      "cordova-plugin-firebase-messaging": {
        "FIREBASE_MESSAGING_VERSION": "20.1.+",
        "ANDROIDX_CORE_VERSION": "1.2.+"
      },
      "cordova-plugin-insomnia": {},
      "cordova-plugin-facebook4": {
        "APP_ID": "660871074774116",
        "APP_NAME": "PrecisApp",
        "FACEBOOK_HYBRID_APP_EVENTS": "false",
        "FACEBOOK_ANDROID_SDK_VERSION": "5.13.0"
      },
      "cordova-plugin-fcm-with-dependecy-updated": {
        "ANDROID_FCM_VERSION": "19.0.0",
        "ANDROID_GRADLE_TOOLS_VERSION": "3.5.3",
        "ANDROID_GOOGLE_SERVICES_VERSION": "4.3.3",
        "ANDROID_SUPPORT_LIBRARY_VERSION": "28.0.0",
        "ANDROID_DEFAULT_NOTIFICATION_ICON": "@mipmap/notification_icon"
      }
    },
    "platforms": [
      "android"
    ]
  }
}

To import the plugin I am doing the following import {FCM} from 'cordova-plugin-fcm-with-dependency-updated/ionic/ngx';

Any help will be very welcome

andrehtissot commented 3 years ago

How is the token being fetched?

By FCM.getToken(), you fetch the current native FCM token. Which might be null if the app wasn't able to receive one from Google yet.

By FCM.onTokenRefresh(), you listen to any changes to the current native FCM token. But if the current value doesn't change, you are not informed of anything, as there was no "FCM token refresh event".

ghost commented 3 years ago

Hello @andrehtissot

The token is retrieved by FCM.getToken ()and as I mentioned through this function I get a valid token, I think the token would not be the problem since in IOS I hear the onNotification event perfectly, the problem is only in Android.

I also have the FCM.onTokenRefresh ()listening, in case the token changes, but it never executes, although I think it is because the token never changes

marwilc commented 3 years ago

i have same this issue in android

andrehtissot commented 3 years ago

Got it... the issue is trying to send a data-only messages.

Unfortunately, there is no consistent way to have a data-only message working without writing the service in java yourself.

marwilc commented 3 years ago

really the problem is that notifications are not received with the application in the foreground

andrehtissot commented 3 years ago

@marwilc, your specific problem doesn't look related to @seguroapp's.