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

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

问题描述

我有这个应用程序,我已经启用了推送通知。我可以通过Firebase控制台发送通知,但是我真正想要做的事情是,在应用上执行操作时,可以向特定用户发送通知。我试着按照Firebase文档,但关于这方面的文件,似乎真的很差..

它告诉你使用这个方法:

<$ p ()函数返回:(字符串),withMessageID:(字符串),timeToLive:(Int64)
FIRMessaging.messaging()。sendMessage(消息:([NSObject:AnyObject] / code>

但是我真的不知道如何将参数作为参数输入,如前所述,文档并不能真正帮助很多..
有没有人试过使用这种方法,如果是的话,它是如何做的?感谢任何帮助,谢谢!

解决方案

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



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


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!

解决方案

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.

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

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

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