question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

iOS showNotificationsWhenInForeground has no effect

See original GitHub issue

When setting showNotificationsWhenInForeground to true, I still not see any notifications on iOS Simulators and physical devices. I only see the console-logs / alerts as a proof that the cloud message is received at all.

My configuration:

  • nativescript-plugin-firebase 10.3.3
  • NativeScript 6.3.2
  • tested on iOS 12 Simulator, iOS 13.3 Simulator, iPhone 6 iOS 12.4 physical device

To reproduce:

  • run the demo of this repository During my tests I only added showNotifications: true, showNotificationsWhenInForeground: true to the firebase-init call.
  • tap the init-Button in the native-api tab of the TabView
  • tap the “add push handlers” button
  • tap the “get push token” Button and put that to the following command
  • run curl -X POST --header "Authorization: key=AAAA9SHtZvM:APA91bGoY0H2nS8GlzzypDXSiUkNY3nrti4st4WOUs_w1A0Rttcx31U90YGv-p3U4Oql-vh-FzZzWUUPEwl47uvwhI4tB5yz4wwzrJA2fVqLEKZpDU42AQppYnU2-dsURqkyc9sKcjay2egWbfyNK2b-G2JQCqrLVA" --Header "Content-Type: application/json" https://fcm.googleapis.com/fcm/send -d "{\"notification\":{\"title\": \"My title\", \"showWhenInForeground\": \"true\", \"content_available\": \"true\", \"text\": \"My text\", \"badge\": \"1\", \"sound\": \"default\"}, \"data\":{\"foo\":\"bar\"}, \"priority\": \"High\", \"to\": \"DEVICE_TOKEN\"}" (it is the same as mentioned in the docs, I only added “content_available”: true and “showWhenInForeground”: true within the notification object)
  • you will see the alert and the console-logs, but no notification

Btw, I cannot test if the notifications work in general, because background notifications work only with physical devices (as mentioned in the docs of the plugin), but I am not able to build the demo app for our physical iPhone 6 due to the build error

error: Failed to register bundle identifier. The app identifier “org.nativescript.firebasedemo” cannot be registered to your development team. Change your bundle identifier to a unique string to try again. (in target ‘demo’ from project ‘demo’) error: Provisioning profile “iOS Team Provisioning Profile: *” doesn’t support the Associated Domains, Push Notifications, and Sign In with Apple capability. (in target ‘demo’ from project ‘demo’) error: Provisioning profile “iOS Team Provisioning Profile: *” doesn’t include the aps-environment

When building our own app for our iPhone 6, I’m not able to test push messages at all, as running the curl says "error":"InvalidApnsCredential". I only see the alert/console-logs for received messages on the Simulator, but there I also do not see any notifications.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8

github_iconTop GitHub Comments

1reaction
felixkrautschukcommented, Apr 1, 2020

@manojdcoder I just created a new nativescript project, installed firebase and tested push-notifications in simulator (using xcode 11.4) and there everything works as expected. The notifications are shown in foreground/background/killed (which is working in our real app as well) and tapping the notification triggers the onMessageReceived callback in all these states…

I don’t know why tapping a notification while app is closed/in background does not trigger the callback in our real app, but it is working in a newly created nativescript app, so it is not a bug in this plugin and the docs are not missing something. It seems to be something in our own app, but no idea what is causing this…

0reactions
felixkrautschukcommented, Apr 1, 2020

@manojdcoder thanks for your hints and your help. Indeed, it was just a missing configuration in the ios app within our Firebase project. Now we see the notifications on our test device in all app states (foreground, background, killed).

Before closing this issue I just want to ask one more thing, as it seems that you have more experience using this plugin: How can we react to the event after tapping a notification?

My config is:

showNotifications: true,
showNotificationsWhenInForeground: true    //iOS only

When the message is received, the onMessageReceivedCallback is called with this message-data:

{
  "google.c.sender.id": <SENDER_ID>,
  "google.c.a.e": "1",
  "gcm.message_id": "1585732400544333",
  "title": "My title",
  "body": "This is the title",
  "data": {
    "google.c.sender.id": <SENDER_ID>,
    "google.c.a.e": "1",
    "aps": {
      "alert": {
        "title": "My title",
        "body": "This is the title"
      },
      "sound": "default"
    },
    "gcm.message_id": "1585732400544333",
    "title": "My title",
    "body": "This is the title"
  },
  "notificationTapped": false,
  "foreground": true
}

When tapping the notification while the app is in foreground, I get the same payload +

"notificationTapped": true,    // --> react to tap event!
"foreground": true

and now I can inject my own logic as mentioned in the plugin-docs…

But what about tapping a notification while the app is in background or killed? When the app is in background, the onMessageReceivedCallback is not called and I just see the notification. When tapping the notification, the callback is not called as well and I just see that the app resumed to foreground. But how can I access the payload in this case?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Firebase push notification not shows when the app at ...
I am using a nativescript-plugin-firebase plugin for the fcm push notification. In the iOS platform, the notification is coming both in the ...
Read more >
App Missing from Settings -> Notifications list - Apple Developer
Hi all, I have the same issue with an IPhone 12 & iOS 14.7 No Notifications option / toggle after installing an app....
Read more >
Simple guide for NativeScript Push Notifications (via ...
Push Notifications provide a way to deliver some information to users while they are not using your app actively. The following use cases...
Read more >
nativescript-push
There is a little quirk: you will currently not get the title and body if the ... Copy that file to app/App_Resources/iOS/ (if...
Read more >
How to fix Family Safety notifications for iOS - Microsoft Support
Check that Family Safety has Notification Access by: ... If your device is running an iOS version 14 or lower, make sure Do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found