[英]What is the best way to send notification user to user ionic 3 / firebase
i am working on a project with ionic 3 and firebase. 我正在使用ionic 3和firebase进行项目。 and i use firebase auth & database.
我使用firebase身份验证和数据库。
what i mean by user to user notification is like "x added you as a friend" or "a new post from x" etc. 我对用户的通知是指“ x将您添加为朋友”或“ x的新帖子”等。
so when i click the add button, app will send a notification to target uid's device. 因此,当我单击添加按钮时,应用程序将向目标uid的设备发送通知。 simple as always.
一如既往的简单。
my question is what is the best and easiest way to do this in ionic & firebase for both ios and android ? 我的问题是在ios和android的ionic&firebase中做到这一点的最佳和最简便方法是什么?
i researched that on the net but there are tons of different ways to do that depend on different platforms i couldnt find specific solution 我在网上进行了研究,但是有很多不同的方法来完成,具体取决于不同的平台,我找不到具体的解决方案
You can do that with FCM . 您可以使用FCM做到这一点。 Add FCM in your project.
在您的项目中添加FCM 。 Now to send notification from user to user/users you need the FCM token/tokens of the another user/users.
现在要从一个或多个用户发送通知,您需要另一个用户的FCM令牌 。 Then just call this API.
然后只需调用此API。
let notifcationObj: any = {
"notification": {
"title": "YOUR_TITLE",
"body" : "x added you as a friend :)",
"sound": "default",
"click_action": "FCM_PLUGIN_ACTIVITY"
},
"data": {
"match": "created",
"matchId": "value2",
"image": "www/assets/img/logo-gray.png"
},
"to": TOKEN/TOKENS(Another user's FCM token or token array),
"priority": "high",
"restricted_package_name": ""
};
let headers = new Headers({
'Content-Type': 'application/json',
'Authorization': 'key=YOUR_FCM_KEY'
});
let options = new RequestOptions({ headers: headers });
let url = "https://fcm.googleapis.com/fcm/send";
this.http.post(url, notifcationObj, options)
.subscribe((data) => {
console.log('notification data -> ', data);
}, (error) => {
console.log('notification error -> ', error);
});
This is best and easiest way to send notification from users end. 这是从用户端发送通知的最佳和最简便的方法。 Let me know if any other help needed.
让我知道是否需要其他帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.