使用 Firebase 和 Swift 推送通知 [英] Push notifications with Firebase and Swift

查看:49
本文介绍了使用 Firebase 和 Swift 推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个应用程序,并且我已经在它上面启用了推送通知.我可以通过 Firebase 控制台发送通知,但我真正想做的是能够在对应用程序执行操作时向特定用户发送通知.我尝试遵循 Firebase 文档,但是有关此的文档似乎真的很差..

I have this app, and I've enabled push notifications on it. I'm able to send notifications through the Firebase console, but what I really wanna do, is to be able to send a notification to specific users, when an action is taken on the app.. I've tried to follow the Firebase docs, but the documentations about this, seems really poor..

它告诉你使用这个方法:

It tells you to use this method:

FIRMessaging.messaging().sendMessage(message: ([NSObject : AnyObject]), to: (String), withMessageID: (String), timeToLive: (Int64))

但我真的不知道要作为参数输入什么,而且如前所述,文档并没有太大帮助..有没有人尝试过使用这种方法,如果是,它是如何完成的?感谢任何帮助,谢谢!

But I can't really figure out what to put in as parameters, and as mentioned, the documentation doesn't really help much.. Have anyone tried using this method, and if yes, how is it done? Appreciating any help, thanks!

推荐答案

据我所知,使用 firebase 的设备无法触发发送推送通知.您需要的是一个单独的服务(在不同的服务器上运行),它具有访问由 firebase 管理的设备令牌并向某些设备发送推送通知的必要权限.所有这些都必须在您的 Nosql firebase 数据库上运行.您可以将您的推送通知请求存储在您的数据库中,并让您的推送通知服务监听该路径.如果有来自设备的请求,则触发发送通知并从数据库中删除请求.

As far as I know it is not possible to trigger sending push notifications from a device with firebase. What you need is a separate service (running on a different server) which has the necessary rights to access the device tokens which are managed by firebase and send push notifications to certain devices. All this will have to run over your Nosql firebase database. You could store your Push notification requests in your database and let your push notification service listen to that path. if there is a request coming in from a device you trigger sending the notification and delete the request from the database.

您可以使用带有此包的 nodejs 应用程序:https://www.npmjs.com/package/fcm-node

you could use a nodejs app with this package: https://www.npmjs.com/package/fcm-node

这篇关于使用 Firebase 和 Swift 推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆