I am using Flutter and I am experiencing a strange behavior when sending notification from the firebase cloud messaging console. If I send a notification to a real device, then the message I get is like this
on message {
google.c.sender.id: 801xxxxx873,
google.c.a.e: 1,
aps: {
alert: {title: Test 33, body: Test test 44}
},
gcm.n.e: 1,
google.c.a.c_id: 10xxxxxx18,
google.c.a.udt: 0,
gcm.message_id: 1592xxxxxxxx6906,
google.c.a.ts: 159xxxxx07
}
If I do the same on the ios simulator I get the following
on message {
from: 80xxxx873,
collapse_key: xxxxx.com.xxxx02,
notification: {
body: Test test 44, title: Test 33, e: 1, tag: campaign_collapse_key_559xxxxxxx002
}
}
Does anyone know why? I believe the first case is in line with apple documentation while the second one is the JSON structure I get when sending to Android
Is there a way to get the same JSON regardless if it is a real device or a simulator?
Thanks
Related
I have an api-platform project.
https://localhost:8888/api does show the API documentation.
When i want to generate the client generator component with the command:
npx #api-platform/client-generator https://127.0.0.1:8000/api . --generator nuxt
I have this response:
{
api: Api { entrypoint: 'https://127.0.0.1:8000/api', resources: [] },
error: {
response: Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: [Object],
[Symbol(Response internals)]: [Object]
}
},
response: Response {
size: 0,
timeout: 0,
[Symbol(Body internals)]: { body: [PassThrough], disturbed: false, error: null },
[Symbol(Response internals)]: {
url: 'https://127.0.0.1:8000/api',
status: 200,
statusText: 'OK',
headers: [Headers],
counter: 0
}
},
status: 200
}
No components have been generated and not sure where to go from there.
I did the setup successfully on my side (until I got a CORS issue probably because I was using https://demo.api-platform.com).
Here is my Github repo for a working client side boilerplate'd Nuxt app that I've got.
Some things are questionable like the usage of Moment.js in 2022, the fact that this is a Nuxt app used as an SPA only (ssr: false), some not up to-date configuration like for nuxt-i18n modules, the components: false, the fact that there are still some ESlint warnings/errors in the various files, the use of an additional vue-i18n package on top of nuxt-i18n but the setup looks kinda okay otherwise.
I mean, at the end it's kinda removing all the nice stuff from Nuxt to have a basic usual Vue.js app as an SPA but yeah, fine let's say.
There is this line in entrypoint.js
export const ENTRYPOINT = 'https://demo.api-platform.com'
Maybe setting this one up to your own local address may work.
If it doesn't, maybe try to host it on Heroku or alike, a real hosted server is maybe needed. Otherwise, it could also be a migration/DB/any-other-backend issue.
It's not an issue on the Nuxt.js side itself at least.
I got a problem,
1 ) I'm using Firebase to send remote Push Notifications, i test by sending from FCM tester.
2 ) I've activated Deep-Linking in my project and started to use it.
3 ) In FCM tester i pass this key value into "notifications.data" :
{ "link" : "MY_LINK" }
Now i want my app to be able to recognize there is a deepLink in it & read it.
Which i achieved to do somehow but not the way i was looking for.
What i did :
NotificationContextProvider.ts
useEffect(() => {
const unsubscribeClosedApp = messaging().onNotificationOpenedApp(
remoteMessage => {
addNotification(remoteMessage);
console.log(
'Notification caused app to open from background state:',
remoteMessage.notification,
);
redirectFromKey(remoteMessage.data?.redirection);
console.log(remoteMessage.data, 'remote message data');
console.log(remoteMessage, 'remote message full');
console.log(remoteMessage.notification?.body, 'remote message body');
console.log(remoteMessage.notification?.title, 'remote message title');
if (remoteMessage.data?.link === 'https://[MY-LINK]/TnRV') {
console.log(remoteMessage.data?.link, 'Deeplink detected & opened');
navigation.navigate({
name: 'Logged',
params: {
screen: 'Onboarded',
params: {
screen: 'LastAnalyse',
},
},
});
}
},
);
And it's working fine but it's not based on reading a link, but by comparing a value and it's not what i'm trying to achieve.
Firebase Doc' give us a way to do this : https://rnfirebase.io/dynamic-links/usage#listening-for-dynamic-links
This is what Firebase suggests :
import dynamicLinks from '#react-native-firebase/dynamic-links';
function App() {
const handleDynamicLink = link => {
// Handle dynamic link inside your own application
if (link.url === 'https://invertase.io/offer') {
// ...navigate to your offers screen
}
};
useEffect(() => {
const unsubscribe = dynamicLinks().onLink(handleDynamicLink);
// When the component is unmounted, remove the listener
return () => unsubscribe();
}, []);
return null;
}
And i have no clue how to make it works.
I got to mention that deep-links are correctly setup in my project and working fine, my code is in Typescript.
Basicaly you can find on this web page what i'm trying to achieve but i want to use Firebase/messaging + Dynamic links. My project don't use local notifications and will never do : https://medium.com/tribalscale/working-with-react-navigation-v5-firebase-cloud-messaging-and-firebase-dynamic-links-7d5c817d50aa
Any idea ?
I looked into this earlier, it seems that...
You can't send a deep link in an FCM message using the firebase Compose Notification UI.
You probably can send a deep link in an FCM message using the FCM REST API. More in this stackoverflow post.
The REST API looks so cumbersome to implement you're probably better off the way you're doing it: Using the firebase message composer with a little data payload, and your app parses the message data with Invertase messaging methods firebase.messaging().getInitialNotification() and firebase.messaging().onNotificationOpenedApp().
As for deep linking, which your users might create in-app when trying to share something, or you might create in the firebase Dynamic Links UI: For your app to notice actual deep links being tapped on the device, you can use Invertase dynamic links methods firebase.dynamicLinks().getInitialLink() and firebase.dynamicLinks().onLink().
I have push notifications working in React Native using #react-native-firebase/messaging. I am using FCM on the backend, and it is currently showing the OS lock screen notifications on iOS and Android.
I want to clear a given notification after a certain time, or after an amount of time has passed. Is there a way to do this? Right now when I send a notification it will stick around for days if I don't click on it. I would like to take a notification down after say an hour, or at 4pm, or whatever. Front-end and/or back-end solutions welcome.
I had assumed that the "ttl" (time to live) parameter did this, but this is not the case.
you could use a background handler like react-native-background-fetch
In your onMessage or backgroundMessage schedule a backgroundTask for your desired time with scheduleTask().
You could use react-native-push-notification to display the notification, which has an method cancelLocalNotifications() to cancel notifications
In the task you could clear the notification depending on the id
PushNotification.configure({
onNotification: (notification) => {
var {id} = remoteMessage.data
BackgroundFetch.configure({
minimumFetchInterval: 15
}, async (taskId) => {
PushNotification().cancelLocalNotifications(id)
BackgroundFetch.finish(taskId);
})
BackgroundFetch.scheduleTask({
taskId: id,
forceAlarmManager: true,
delay: 5000
});
}
})
TTL parameter only specifies the delivery of the notification to the user device. E.g. Still deliver the message after the phone was offline for 2 hours or not.
I'm not sure if there is a way with the default firebase package, but the more advanced version of it seems to be able to handle that use case:
https://notifee.app/react-native/reference/canceldisplayednotification
I think you should be able to call that method in a background task (e.g. after receiving another (silent) notification).
Unfortunately I couldn’t test it myself yet.
On iOS you you can use the badge setting. If you set it to 0, it will remove all notifications. For your case you could schedule a "cleanup" task that triggers the below request after a certain amount of time.
{
message: {
notification: {
body: "" // has to be empty
},
android: {
notification: {
channel_id: 'some_channel'
}
},
apns: {
payload: {
aps: {
category: 'some_category',
badge: 0
}
}
},
token: device_token
}
}
Unfortunately, I have not found a similar solution for android yet.
I have created this function in Google Cloud Platform associated with Firebase Realtime Database. The function sends a notification to mobile applications when something appears in the database.
As you can see below I set the priorities so that the notification will be noticed by the user
var message = {
token: tokenSnapshot,
notification: {
title: "Title",
body: "Body",
},
android: {
priority: 'high',
notification: {
sound: 'default',
priority: 'high',
visibility: 'public'
}
},
};
Unfortunately, it doesn't do anything. The notification comes but the user sees when he checks manually if something has come
I use a standard approach in the application
messaging().enable.setBackgroundMessageHandler(async remoteMessage => {
console.log('Message handled in the background!', JSON.stringify(remoteMessage));
})
Is there any way for notifications to be with sound, vibration and to appear on the lock screen?
I haven't used the react-native-push-notification library yet. Can this library help in this?
If you are using firebase-cloud messaging i suggest using firebase in your app.
https://rnfirebase.io/messaging/usage
Make sure you follow the initial set up first.
Please read more about this here. https://rnfirebase.io/
I'm using the pubsub library from an ESP8266 NodeMCU and the Arduino IDE.
https://github.com/knolleary/pubsubclient/tree/master/examples/mqtt_esp8266
My device is registered with the IBM Bluemix IoT Foundation (IoTF).
The client name I'm using is
char* myclient = "d:ORGID:Devicetype:Deviceid";
Where orgid is my orgID from Bluemix and the Device type and id are from the device I created and registered in the IoTF. The topic I'm posting to is by this line in my code:
client.publish("iot-2/evt/status/fmt/json", msg);
In Node-RED I have an IOT-in node looking at Device Status and using the Bluemix service for auth.
I am seeing this error when I put a debug node looking at the complete message object from the IoT-in node (note: I changed my orgid to ORGID in this debug output):
{
"_msgid": "9f433f7b.60bcc",
"deviceId": "InterConnect",
"deviceType": "nodeMCU",
"payload": {
"Action": "Disconnect",
"ClientAddr": "24.47.149.38",
"ClientID": "d:ORGID:nodeMCU:InterConnect",
"CloseCode": 276,
"ConnectTime": "2016-02-14T18:32:19.328Z",
"Port": 1883,
"Protocol": "mqtt4-tcp",
"ReadBytes": 111,
"ReadMsg": 0,
"Reason": "The topic is not valid.",
"SecureConnection": false,
"Time": "2016-02-14T18:32:19.397Z",
"User": "use-token-auth",
"WriteBytes": 4,
"WriteMsg": 0
},
"topic": "iot-2/type/nodeMCU/id/InterConnect/mon"
}
I'm wondering how my topic got changed to what it's showing here. Any ideas?
This was occurring because my code was subscribing to "iot-2/evt/command_id/fmt/format_string" instead of "iot-2/cmd/command_id/fmt/format_string" - once I fixed that, everything flowed fine.