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

Google FCM Push Notifications Cordova Plugin
MIT License
209 stars 277 forks source link

getInitialPayload is always null #223

Open simonklinge opened 3 years ago

simonklinge commented 3 years ago

Describe the bug After tapping the notification the app will come to foreground but the InitialPayload is not set. While debugging the android project it seems that the FCMPluginActivity is never created. (onCreate is never called)

Also on iOS getInitialPayload data is always null. However, on iOS the onNotification event fires, so it is no problem here.

Environment Plain cordova. No ionic.

Payload our incoming payload looks like this ('onNotification' result):

"wasTapped":false,
"siteId":"638583848",
"notificationType":"Message",
"alertKey":"0~T~8584cbc0-429f-4490-927c-0d124dd7bbad...",
"title":"Axis Strasse Bewegung",
"click_action":"FCM_PLUGIN_ACTIVITY"

so the click action is set

Package.json of the cordova project I created a new project to replicate this issue:

{
  "name": "io.cordova.hellocordova",
  "displayName": "HelloCordova",
  "version": "1.0.0",
  "description": "A sample Apache Cordova application that responds to the deviceready event.",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [
    "ecosystem:cordova"
  ],
  "author": "Apache Cordova Team",
  "license": "Apache-2.0",
  "devDependencies": {
    "cordova-android": "^9.0.0",
    "cordova-plugin-device": "^2.0.3",
    "cordova-plugin-fcm-with-dependecy-updated": "^7.7.0",
    "cordova-plugin-whitelist": "^1.3.4"
  },
  "cordova": {
    "plugins": {
      "cordova-plugin-whitelist": {},
      "cordova-plugin-fcm-with-dependecy-updated": {
        "ANDROID_DEFAULT_NOTIFICATION_ICON": "@mipmap/ic_launcher",
        "ANDROID_FCM_VERSION": "21.0.0",
        "ANDROID_FIREBASE_BOM_VERSION": "26.0.0",
        "ANDROID_GOOGLE_SERVICES_VERSION": "4.3.4",
        "ANDROID_GRADLE_TOOLS_VERSION": "4.1.0"
      },
      "cordova-plugin-device": {}
    },
    "platforms": [
      "android"
    ]
  }
}

config.xml of the cordova project

<?xml version='1.0' encoding='utf-8'?>
<widget id="de.***.app" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>HelloCordova</name>
    <description>
        A sample Apache Cordova application that responds to the deviceready event.
    </description>
    <author email="dev@cordova.apache.org" href="http://cordova.io">
        Apache Cordova Team
    </author>
    <content src="index.html"/>
    <plugin name="cordova-plugin-whitelist" spec="1"/>
    <access origin="*" subdomains="true"/>
    <allow-navigation href="*"/>
    <allow-intent href="http://*/*"/>
    <allow-intent href="https://*/*"/>
    <allow-intent href="tel:*"/>
    <allow-intent href="sms:*"/>
    <allow-intent href="mailto:*"/>
    <allow-intent href="geo:*"/>
    <platform name="android">
        <allow-intent href="market:*" />
        <preference name="android-minSdkVersion" value="26"/>
        <preference name="android-targetSdkVersion" value="29"/>
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
</widget>

Any help is much appreciated :)

fleerdayo commented 3 years ago

I think getInitialPayload() gets triggered when the app is opened by clicking on the notification from killed state, not background state.

Killed state on ios means, that the app is not running in the background.

RidClick commented 3 years ago

The getInitialPushPayload only load if the app has a notification that was erased from notification center. Try whit this.fcm.getInitialPushPayload().then(data => { if(data != null) { // show data }}) .catch(e => console.log('ErrorPayload', e))

GroupeBEL commented 3 years ago

Hello,

I'm having the same problem, the app is killed -> getInitialPushPayload data null I'm using the last version of plugin + ionic 5 @RidClick I used that but same, when I click the notification it opens the application but still having null

GroupeBEL commented 3 years ago

Update

->setNotification(AndroidNotification::create()->setClickAction('FCM_PLUGIN_ACTIVITY')) --> this line solved the problem (using laravel)

petrot commented 3 years ago

Same problem here, but only on Android.. On iOS, getInitialPushPayload() returns with an object. On Android, it returns only with null.

raghav14 commented 3 years ago

Is there any solution for this? If not then which version is stable to use? @andrehtissot

chaymankala commented 3 years ago

Is there any update on this issue?

ap1969 commented 3 years ago

Thanks to @GroupeBEL at https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated/issues/223#issuecomment-785798244 - this solution worked for me as well.

Stack: Android app running Vue (Quasar framework), notifications sent via npm's firebase-admin package

petrot commented 2 years ago

Is there any solution for this bug? I send message from the Firebase console, and the initialPayload is null (I tried to add "click_action":"FCM_PLUGIN_ACTIVITY" as custom data, but not helped..)

Khazbs commented 2 years ago

I am experiencing this problem on Android too