I am using a simulator running iPhone X with iOS version 11.3 which receives notifications when sent in the foreground but is not able to receive anything when the app is in the background ( not closed ).
I have tried a data only payload as well as a data and notification payload, the only time the notification is received is when the app is in the foreground.
I have a physical device running iOS version 9.3 which receives the same fcm in the background.
Application Target Platform:iOS
Development Operating System:macOS High Sierra
Build Tools:Xcode 9.3 (9E145)
React Native version:0.55.0
RNFirebase Version: 4.0.1
Firebase Module:Firebase Messaging , Firebase Notifications
Remote notifications do not work on the iOS simulator.
This is a restriction by Apple, as explained at the top of the installation notes: https://rnfirebase.io/docs/v4.0.x/notifications/ios
@chrisbianca a little noob question here, when you say remote notification, is it a different kind of notification that is sent when the app is in the foreground and a different one when the app is in the background of a simulator because as of now I am receiving a notification on the simulator when the app is in the foreground.
When in the foreground, FCM connects directly to the google servers and bypasses APNS which is why notifications work on the simulator.
When in the background, this connection doesn't exist so google uses APNS (Apple Push Notification Service) which doesn't work on the simulator.
@chrisbianca Thank you 馃 馃憤
@chrisbianca tried the above code on a physical device [ iPhone 4s ] running iOS version 9.3.5.
It fails to receive any data only payload when in background but receives a data only payload when in foreground.
I modified my send request to include a notification payload along with a data payload, after this I did begin receiving the fcm which would automatically create the notification based on the notification payload being supplied but I do not get any callbacks in my app when this happens.
I have implemented the onNotification
, onNotificationDisplayed
and onMessage
and the onNotificationDisplayed
callback gets called. I would like the onMessage
to be called when the app is in the background by sending a data only payload but this isn't happening.
If it helps, in my iOS logs when i send a data + notification payload to an app that is in the background i get a log which says Unknown aps key: content-available
.
This is what my send request looks like
{
'to' : "/topics/topic_name",
'priority' : "high",
'collapse_key' : "alerts",
'time_to_live' : 120,
"content_available" : true,
"notification" : {
"title" : "Fetching New Alerts",
"body" : "Please Wait"
},
"data" : {
ALERTS_FETCH : true
}
}
@Salakar same here, have u found the solution ?
Spoken to @judemanutd offline, he's confirmed this is no longer and issue.
@hai2014bk use the onTokenRefresh
method to get the actual token.
I was initially using firebase.messaging().getToken()
to get my token but encountered some issues, instead switch to onTokenRefresh
.
componentDidMount() {
this.onTokenRefreshListener = firebase.messaging().onTokenRefresh(fcmToken: string => {
// Process your token as required
});
}
componentWillUnmount() {
this.onTokenRefreshListener();
}
Once the token is generated you can use that token to send the device a message directly or if you use topic write the code to subscribe to a topic within the onTokenRefresh
.
@judemanutd I have the same problem while sending notifications to a topic.
How can I workaround this situation?
@maggialejandro what exactly is the issue? Notifications work fine, the only issue is processing the notifications in the background.
@judemanutd exactly, notifications works correctly on foreground but they aren't shown when the app is in background/killed. They are shown the next time the app is opened.
I've created an issue with more details.
Most helpful comment
When in the foreground, FCM connects directly to the google servers and bypasses APNS which is why notifications work on the simulator.
When in the background, this connection doesn't exist so google uses APNS (Apple Push Notification Service) which doesn't work on the simulator.