Nativescript-plugin-firebase: iOS: onMessageReceivedCallback not being called if notification is received in background

Created on 24 Jul 2018  路  21Comments  路  Source: EddyVerbruggen/nativescript-plugin-firebase

If my app is open, the callback is called.
If the app is in the background, I receive the notification, but when I open the app the callback is not called.

I have required the plugin in main.ts before start(), and init after start in app.component. Here's the trace:
I get this when I receive the notification when the app is in the background:

[com.presonus.mypresonus] Did deliver 1 notifications
Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.

then when I open the app i get this:
TCP Conn [12:0x1c037a7c0] using empty proxy configuration Stream client bypassing proxies on TCP Conn [12:0x1c037a7c0] TCP Conn 0x1c037a7c0 started [12 <private> <private>] start 0x14cb0de18 - UIProcess is taking a foreground assertion because the view is visible 0x10c334210 - ProcessThrottler::updateAssertionNow() updating process assertion state to 2 (foregroundActivities: 1, backgroundActivities: 0) 0x1c4674fc0 - ProcessAssertion::setState(2) 0x1c4651070 - WKProcessAssertionBackgroundTaskManager - beginBackgroundTaskWithName 0x10c334000 - WebProcessProxy::didSetAssertionState(Foreground) taking foreground assertion for network process 0x10c30c138 - ProcessThrottler::updateAssertionNow() updating process assertion state to 2 (foregroundActivities: 1, backgroundActivities: 0) 0x1c0477200 - ProcessAssertion::setState(2) NSURLConnection finished with error - code -1002 TCP Conn 0x1c037a7c0 event 1. err: 0 TCP Conn 0x1c037a7c0 complete. fd: 16, err: 0 TCP Conn 0x1c037a7c0 starting SSL negotiation TCP Conn 0x1c037a7c0 SSL Handshake DONE [com.presonus.mypresonus] Setting badge number to 0 [com.presonus.mypresonus] Set badge number [ hasCompletionHandler: 0 hasError: 0 ] Status bar could not find cached time string image. Rendering in-process.

Any idea whats going on? Thanks Eddy 鉂わ笍

Most helpful comment

@EddyVerbruggen @BMwanza @VolodymyrVA @Lacos247 Nice, this works now! Maybe a combination of the updates made recently and moving init out of app.component.ts
Thanks everyone 鉂わ笍

All 21 comments

Some more info:
this: curl -X POST --header "Authorization: key=MYSERVERKEY" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"data\":{\"foo\":\"bar\"}, \"priority\": \"High\", \"content_available\":true, \"to\": \"DEVICETOKEN\"}"
gets me this in the background: Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.
but the callback isnt called when the app is opened.

This:
curl -X POST --header "Authorization: key=SERVERKEY" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"notification\":{\"title\": \"My title\", \"text\": \"My text\", \"badge\": \"1\", \"sound\": \"default\"}, \"data\":{\"foo\":\"bar\"}, \"priority\": \"High\", \"to\": \"DEVICETOKEN\"}"
triggers onMessageReceivedCallback when the app is in the foreground, and gives me the data i pass (foo:bar)
However, when in the background, I receive the notification on my device, but when I tap it to open the app, onMessageReceivedCallback is NOT called, i do however get this among other things in the console: [MYAPPID] Did deliver 1 notifications.

If I pass content_available: true with a data only notification, onMessageReceivedCallback is not called when the app is open.

If I pass content_available: true with data and notification, and the app is in the foreground, onMessageReceivedCallback is called, however if its in the background the notification is delivered, i tap on it, and onMessageReceivedCallback is NOT called. I get this though:
Warning: Application delegate received call to -application:didReceiveRemoteNotification:fetchCompletionHandler: but the completion handler was never called.

Any progress on this? This is exactly the issue i am also experiencing under iOS.

Glad I am not alone. I have been debugging for days, I cannot figure this out

Yes you are not alone. I have no solution for this.
If I implement it native then it works out of the box. I still have no solution for this.

It works on android, when I tap the notification that I received in the background, the callback is executed. @EddyVerbruggen I know you probably regret creating this plugin haha, but do you have any ideas/suggestions? I've followed the instructions to the letter.

I do. Esp notifcations. The only issues folks report are about freakin notifications.

I鈥檓 on vacation so trying to ignore this for now.

Ok definitely ignore! Enjoy your vacation 鉂わ笍

@EddyVerbruggen any chance youve had time to look at this?

Nope

@davecoffin Any progress on this? I am battling this as well

Unfortunately not.

@davecoffin If you don't mind me asking then, are you using some alternative to get Push Notifications working in your NativeScript app then?

No, I'm using this plugin and my app just doesnt support deep links from notifications until this issue is fixed.

Hi guys!
Any progress on this?

Not to my knowledge. @EddyVerbruggen I noticed a lot of commits, any chance one of the version releases addresses this?

@VolodymyrVA @davecoffin Hey guys I was actually able to resolve this by moving firebase.init() out of my app.js file. Keep in mind that if you do this though, you will still need to require() the firebase module in app.js

@BMwanza I think what you describe is also what's recommended in the readme.
@davecoffin I didn't specifically fix anything related to this (because I can't reproduce it with the demo app in this repo), but chances are it helped because, indeed, a lot of changes were made.

@EddyVerbruggen @BMwanza @VolodymyrVA @Lacos247 Nice, this works now! Maybe a combination of the updates made recently and moving init out of app.component.ts
Thanks everyone 鉂わ笍

Awesome, thanks for the feedback!

@EddyVerbruggen @davecoffin @BMwanza @Lacos247 thanks everyone!
This works!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

thunder413 picture thunder413  路  3Comments

romandragan picture romandragan  路  3Comments

bunower picture bunower  路  3Comments

ButterMeWaffle picture ButterMeWaffle  路  4Comments

phatakrajan picture phatakrajan  路  4Comments