iOS showNotificationsWhenInForeground has no effect
See original GitHub issueWhen 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:
- Created 4 years ago
- Comments:8
Top GitHub Comments
@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…
@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:
When the message is received, the onMessageReceivedCallback is called with this message-data:
When tapping the notification while the app is in foreground, I get the same payload +
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?