简体   繁体   English

将通知用户发送到用户ionic 3 / firebase的最佳方法是什么

[英]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.

相关问题 Ionic 4 + Firebase - 发送通知用户聊天应用 - Ionic 4 + Firebase - Send Notification User Chat App 跨Ionic标签管理Firebase用户的最佳方法是什么 - What is the best way to manage Firebase user across Ionic Tabs 是否可以将FCM通知发送给Firebase DB中输入的用户数据? - Is there a way to send FCM notification to a user data input in Firebase DB? 在 API Authorization 标头中从前向后发送 firebase 用户令牌的最佳方法是什么? (NextJs 应用程序) - What is the best way to send firebase user token from front to back in API Authorization header ? (NextJs Application) 在小部件中设置Firebase Crash用户标识符的最佳方法是什么? - What is the best way to set a Firebase Crash user identifier in a widget? 检查用户是否是firebase auth中的新用户的最佳方法是什么? - What is the best way to check if the user is new in firebase auth with flutter Firebase:在所有设备上向用户发送推送通知 - Firebase: Send push notification to user on all their devices Firebase向iOS上的用户细分发送通知无法正常工作 - Firebase Send a Notification to a User Segment on iOS not working 快速从用户到用户Firebase发送推送通知 - Swift Send Push Notification from user to user Firebase 如何基于用户属性用户发送Firebase云消息传递通知? - How to send firebase cloud messaging notification based on user property user?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM