如何使用Firebase云消息传递和云功能设置推送通知?

发布于 2025-01-29 04:59:25 字数 366 浏览 2 评论 0 原文

我已经编码了一年,并且非常了解Swift和JavaScript的基础知识。我构建了一个像应用这样的社交媒体,除了推送通知功能之外,它已经完全完成了……我已经挣扎了一段时间。

我很难弄清楚如何实现这些信息以发送通知,例如用户关注另一个用户或收到新的Messege。

我不明白如何将我将使用node.js编写的云功能与我的Xcode项目进行整合。

当我在线寻找文档时,通常只是如何使用Firebase Notifications Console发送推送通知,该通知酷,但不会触发基于特定用户操作或事件的触发(例如:当用户获得新的关注者时),

我认为既然IM正在努力通过掌握如何实施它的概念,它的实际技术设置甚至不太重要。任何建议或资源将不胜感激。

谢谢

I'm been coding for a year now and know swift really well and the basics to javascript. I've built a social media like app and its completely done besides the push notification functionality... which i've been struggling with for quite a while now.

I'm having trouble figuring out how to implement these in order to send notifications like when a user follows another user or they receive a new messege.

I don't understand how to integrate the cloud functions that I would write using and node.js with my xcode project.

When I look for documentation online its usually just how to send push notifications using the firebase notifications console which is cool but doesn't trigger based off specific user actions or events (ex: when the user gets a new follower)

I think since im struggling with grasping the concept of how to implement it, the actual technical set up of it makes even less sense. Any advice or resources would be greatly appreciated.

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深白境迁sunset 2025-02-05 04:59:25

从概念上讲,您要做的就是在事件发生时设置数据库的服务器端处理以管理。这就是node.js代码的目标。一切都通过数据库连接 - 您的Xcode和node.js代码独立工作,但都与Firebase通信。您可以创建一个云功能,该功能将在检测数据库中的更改时自动运行,这将自动发送推送通知。

我已经完成了一个类似的项目 - 我在云功能中为实时数据库设置了一个侦听器。每当用户获得新的追随者时,即更新了他们的关注者树,我就使用FCM令牌向设备发送了通知(我也存储在数据库中)。

exports.onTimeEnd = functions.database.ref("users/{user}/followers")
    .onUpdate((snapshot, context) => {
  // your code here
}

在该块中,您可以调用 .once()以找出用户的令牌以向其发送通知。

此处的此链接告诉我有关在终端中设置的一切都必须做的。超级有帮助。

Conceptually, what you have to do is set up server-side processing of your database to manage when events occur. This is what the Node.js code will be. Everything is connected through the database-- your Xcode and Node.js code work independently, but both communicate with Firebase. You can create a Cloud Function that will automatically run when it detects changes in your database, and this will automatically send push notifications.

I've done a similar project-- I set up a listener for my Realtime Database in my Cloud Function. Every time the user got a new follower, i.e. their followers tree was updated, I sent a notification to the device using an FCM token (which I also stored in the database).

exports.onTimeEnd = functions.database.ref("users/{user}/followers")
    .onUpdate((snapshot, context) => {
  // your code here
}

In that block, you can call a .once() to find out the user's token to send them a notification with.

https://firebase.google.com/docs/functions/get-started

This link here told me everything I had to do in regards to set up in the terminal. Super helpful.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文