EddyVerbruggen / nativescript-plugin-firebase

:fire: NativeScript plugin for Firebase
https://firebase.google.com
MIT License
1.01k stars 446 forks source link

Can't find variable: FIRMessaging ; Zone: <root> ; #1003

Closed waynerobinson closed 5 years ago

waynerobinson commented 5 years ago

I have started getting the following error on start-up and not sure what's changed that may cause this.

CONSOLE ERROR file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:676:30: Unhandled Promise rejection: Can't find variable: FIRMessaging ; Zone: <root> ; Task: null ; Value: ReferenceError: Can't find variable: FIRMessaging file:///app/tns_modules/nativescript-plugin-firebase/messaging/messaging.js:420:21
EddyVerbruggen commented 5 years ago

Please share a repo so this can be reproduced. But please first try the latest plugin version.

rickybrown commented 5 years ago

this is the exact error I'm getting, was this resolved already or just closed for inactivity?

EddyVerbruggen commented 5 years ago

@rickybrown I did ‘t get that with your test repo. Do I have to send a certain payload to the device in order to reproduce it?

rickybrown commented 5 years ago

@EddyVerbruggen that might be the case, i notice i'm getting the alert message but the APNS data payload is not coming through. Gotta run, later I will spend some time testing it out with a payload on the test repo. I appreciate your work on this plugin, will get back on after I've dug in some more. Everything else seems to be working as it should

rickybrown commented 5 years ago

@EddyVerbruggen These are my logs upon initializing the application, without sending/receiving any push notifications or taking any other actions, you'll see the error just a few lines down from the top:

CONSOLE LOG file:///app/tns_modules/@angular/core/bundles/core.umd.js:3191:24: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
CONSOLE LOG file:///app/tns_modules/@angular/core/bundles/core.umd.js:3890:43: Registered for push
CONSOLE ERROR file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:676:30: Unhandled Promise rejection: Can't find variable: FIRMessaging ; Zone: <root> ; Task: null ; Value: ReferenceError: Can't find variable: FIRMessaging file:///app/tns_modules/nativescript-plugin-firebase/messaging/messaging.js:420:21
ZoneAwarePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:902:37
_messagingConnectWithCompletion@file:///app/tns_modules/nativescript-plugin-firebase/messaging/messaging.js:419:23
file:///app/tns_modules/nativescript-plugin-firebase/messaging/messaging.js:213:44
UIApplicationMain@[native code]
start@file:///app/tns_modules/tns-core-modules/application/application.js:272:26
run@file:///app/tns_modules/tns-core-modules/application/application.js:300:10
bootstrapNativeScriptApp@file:///app/tns_modules/nativescript-angular/platform-common.js:153:26
bootstrapApp@file:///app/tns_modules/nativescript-angular/platform-common.js:87:38
bootstrap<…>
...

Upon receiving a push notification, whether I do or do not send a payload, this is the message object that is logged:

CONSOLE LOG file:///app/app/services/notifications/push.service.js:23:28: Push message received
CONSOLE LOG file:///app/app/services/notifications/push.service.js:24:28: {
"data": {
  "aps": {
      "alert": "my push message to display"
  }
},
"foreground": true
}

And although this piece is irrelevant to the plugin - just for info - I'm using AWS SNS and this is how the message and payload are constructed:

const payload = {
    aps: {
      alert: message,
      badge: 1,
      sound: "default"
    },
    source: source,
    starttime: Math.floor(Date.now()/1000) + 2000,
    obj: obj
  }
  const msgObj = {
    default: message,
    APNS: payload,
    APNS_SANDBOX: payload
  }
  return sns.publish({
    TargetArn: endpoint,
    MessageStructure: 'json',
    Message: JSON.stringify(msgObj)
  }).promise();

I used Ionic before switching to NativeScript, This is the backend service that I use to receive notifications in the Ionic version of this app

I must admit I haven't had a chance to do this with the test repo yet, won't be able to until after work, but thought I'd post this info

EddyVerbruggen commented 5 years ago

Thanks. I can take a look this sunday.

rickybrown commented 5 years ago

@EddyVerbruggen thanks. I can confirm that I am also getting the same error on the test repo, and also receiving the same message object without the additional APNS payload

EddyVerbruggen commented 5 years ago

Hey @rickybrown, I've fixed that FIRMessaging error, although that shouldn't actually hamper the plugin's functionality.

I'm not entirely sure what the issue with the payload is you reported above ("..this is the message object that is logged:.."). What's the actual problem here? If there is an issue, please update your https://github.com/rickybrown/ns-angular-push project and I'll take a look.

rickybrown commented 5 years ago

@EddyVerbruggen awesome thanks. I guess what I need to know is - are you able to push a payload and receive the data? The log shows that I can receive alert text, but I'm trying to also receive additional data, here's an example payload from apple's website (are you able to push an object like this and receive all the data in your app?):

{
    "aps" : {
        "alert" : "You got your emails.",
        "badge" : 9,
        "sound" : "bingbong.aiff"
    },
    "acme1" : "bar",
    "acme2" : 42
}

note this question is unrelated to the thread's issue that you fixed

rickybrown commented 5 years ago

I cloned the plugin, trying to play with it

EddyVerbruggen commented 5 years ago

Hey @rickybrown, I'm using the macOS Pusher app to test payloads, and when sending this to my iOS device with the demo-push repo:

{
  "aps": {
    "alert": "Testing.. (1)",
    "badge": 1,
    "sound": "default",
    "foo": "bar"
  },
  "foo2": "bar2"
}

I receive this in my app's code through the plugin:

{
  "foo2": "bar2",
  "data": {
    "aps": {
      "foo": "bar",
      "alert": "Testing.. (0)",
      "badge": 1,
      "sound": "default"
    },
    "foo2": "bar2"
  },
  "foreground": true
}

Note that foo2 is in there twice because the plugin copies stuff from the data object to a higher level, but that's beside the point. So AFAIK you should be able to extract your acme1 and acme2 values from the payload.

EddyVerbruggen commented 5 years ago

Btw, 7.4.3 has been released a minute ago.

rickybrown commented 5 years ago

@EddyVerbruggen you are right, I tried with pusher app and it does work. I'm not sure why that data sent from AWS SNS interface doesn't come through - only the message text does. It's clearly not a problem with the plugin, so I'll have to figure the rest out myself. Thanks for all your help!

rickybrown commented 5 years ago

@EddyVerbruggen I was able to modify the AWS options in my server code to get the payload sent through successfully. I am smooth sailing now. Thanks!

EddyVerbruggen commented 5 years ago

Great to hear!