ios 使用 Firebase 实施推送通知的最佳方式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34660876/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 08:32:27  来源:igfitidea点击:

Best way to implement push notifications with Firebase

iospush-notificationfirebasezapierpushover

提问by Philip Sopher

I am an iPhone app coder, and I'm using Firebase as my backend server. Firebase doesn't support Push Notifications, so I've been trying to figure out how to include them in my app. I've read this question: How to send an alert message to a special online user with firebasebut it seems like more of a work-around than an actual solution.

我是一名 iPhone 应用程序编码员,我使用 Firebase 作为我的后端服务器。Firebase 不支持推送通知,所以我一直在努力弄清楚如何将它们包含在我的应用程序中。我读过这个问题:How to send a alert message to a special online user with firebase但它似乎更像是一种解决方法,而不是实际的解决方案。

Is there an answer on how to do this? Are there third parties or APIs that might seemlessly implement this functionality?

有没有关于如何做到这一点的答案?是否有第三方或 API 可以无缝地实现此功能?

One solution I have tried is to use Zapier to connect Firebase to Pushover.

我尝试过的一种解决方案是使用 Zapier 将 Firebase 连接到 Pushover。

At this point, I've been able to observe events in the app that I'm coding and then get notifications in a pushover app on my iphone. However, ideally, I'd like to receive the notifications in my app, not in the pushover app, because I don't want users to need to have pushover in order to use my app and because I want users to receive their own distinct notifications, not notifications for everyone.

在这一点上,我已经能够观察我正在编写的应用程序中的事件,然后在我的 iphone 上的 pushover 应用程序中收到通知。但是,理想情况下,我希望在我的应用程序中接收通知,而不是在 pushover 应用程序中,因为我不希望用户需要 pushover 才能使用我的应用程序,并且因为我希望用户收到他们自己独特的通知,而不是针对所有人的通知。

Does anyone have suggestions on how I should handle this issue?

有没有人对我应该如何处理这个问题提出建议?

Thanks for the help!

谢谢您的帮助!

EDITThis isn't a duplicate of this question: Does firebase handle push notifications?because I know Firebase doesn't directly handle push notifications. I'm looking for the best indirect way of handling push notifications with Firebase.

编辑这不是这个问题的重复:Does firebase handle push notification? 因为我知道 Firebase 不直接处理推送通知。我正在寻找使用 Firebase 处理推送通知的最佳间接方式。

回答by JúlioCézar

Now Google rebranded GCM to Firebase Cloud Messagingand it now offers this cross platform service. Firebase also offers notifications.

现在 Google 将 GCM 更名为Firebase Cloud Messaging,并且现在提供这种跨平台服务。Firebase 还提供通知

These are the differences between these two services:

这些是这两种服务之间的区别:

Firebase Cloud Messaging provides a complete set of messaging capabilities through its client SDKs and HTTP and XMPP server protocols. For deployments with more complex messaging requirements, FCM is the right choice.

Firebase Notifications is a lightweight, serverless messaging solution built on Firebase Cloud Messaging. With a user-friendly graphical console and reduced coding requirements, Firebase Notifications lets users easily send messages to reengage and retain users, foster app growth, and support marketing campaigns.

Firebase Cloud Messaging 通过其客户端 SDK 以及 HTTP 和 XMPP 服务器协议提供了一套完整的消息传递功能。对于具有更复杂消息传递要求的部署,FCM 是正确的选择。

Firebase 通知是一种基于 Firebase 云消息传递的轻量级无服务器消息传递解决方案。借助用户友好的图形控制台和减少的编码要求,Firebase 通知让用户可以轻松发送消息以重新吸引和留住用户、促进应用增长并支持营销活动。

If you want a more detailed comparison. Read this.

如果你想要更详细的比较。读这个

回答by n6xej

If you want device to device push messages and not just server to device, the only solution I found was OneSignal. I was able to add basic device to device push message support for my app in about an hour and it is currently free.

如果您希望设备到设备推送消息而不仅仅是服务器到设备,我找到的唯一解决方案是OneSignal。我能够在大约一个小时内为我的应用程序添加基本设备到设备推送消息支持,它目前是免费的。

Both Batch and Firebase only support server to device push messages, not what you want for a chat app

Batch 和 Firebase 都只支持服务器到设备推送消息,而不是你想要的聊天应用程序

回答by Jay

There are a couple of options: (well, more than a couple but here's two)

有几个选择:(嗯,不止一对,但这里有两个)

Parse handles push notifications very very well - they have that down pat and it's super simple. However, you may have issues with users and accounts - depending on what your app does.

Parse 非常好地处理推送通知 - 他们有这样的功能,而且非常简单。但是,您可能会遇到用户和帐户问题 - 取决于您的应用程序的功能。

You mentioned Pushover. We worked their API a while back but not through Zapier. If I remember correctly, I believe you can simply register your app, send an HTTPS: request to their server and then the notifications are sent from/to your app.

你提到了 Pushover。不久前我们使用了他们的 API,但不是通过 Zapier。如果我没记错的话,我相信您可以简单地注册您的应用程序,向他们的服务器发送 HTTPS: 请求,然后从您的应用程序发送通知/向您的应用程序发送通知。

Also, you may want to evaluate how you are using push as it's possible you can roll a notification-like event just into the app itself.

此外,您可能想要评估您如何使用推送,因为您可以将类似通知的事件滚动到应用程序本身中。

回答by Philip Sopher

Here's the answer I got from the Firebase team:

这是我从 Firebase 团队得到的答案:

Firebase currently does not have push notification feature. You can use Firebase Queue and GCM to implement push notification in your app. Queues can be used in your Firebase app to organize workers or perform background work like generating thumbnails of images, filtering message contents and censoring data, or fanning data out to multiple locations in your Firebase database. Google Cloud Messaging (GCM) is a free service that enables developers to send messages between servers and client apps and it is available in both iOS and Android.

Firebase 目前没有推送通知功能。您可以使用 Firebase Queue 和 GCM 在您的应用中实现推送通知。您可以在 Firebase 应用中使用队列来组织工作人员或执行后台工作,例如生成图像缩略图、过滤消息内容和数据,或将数据散布到 Firebase 数据库中的多个位置。Google Cloud Messaging (GCM) 是一项免费服务,可让开发人员在服务器和客户端应用程序之间发送消息,它在 iOS 和 Android 中均可用。

You can push an object with some data to the /queue/tasks location in your Firebase using any Firebase client or the REST API. Workers listening at that location will automatically pick up and process the job. From that, your workers can make a GCM push notification.

您可以使用任何 Firebase 客户端或 REST API 将带有一些数据的对象推送到 Firebase 中的 /queue/tasks 位置。在该位置收听的工作人员将自动接听并处理工作。从中,您的工作人员可以发出 GCM 推送通知。

(end of message from Firebase team)

(来自 Firebase 团队的消息结束)

~~~~~~~~~

~~~~~~~~~

Here's my analysis:

这是我的分析:

It seems like there are a few solutions, but the two best ones are:

似乎有几个解决方案,但最好的两个是:

1) Use FirebaseQueue with Google Cloud Messaging.

1) 将 FirebaseQueue 与 Google Cloud Messaging 结合使用。

2) Leverage the Push Notification functionality in Parse within the Firebase app.

2) 在 Firebase 应用程序中利用 Parse 中的推送通知功能。

I'm not sure which is better. Parse seems more proven, but Firebase Queue is more-easily integrated into the app (ie. it's nice have everything on Firebase and not having to set up a Parse app)

我不确定哪个更好。Parse 似乎更成熟,但 Firebase Queue 更容易集成到应用程序中(即,Firebase 上的所有内容都很好,而不必设置 Parse 应用程序)

Anyways, I hope this thread helps out other people!

无论如何,我希望这个线程可以帮助其他人!

回答by felixwcf

Just realized that they've come out this:

刚刚意识到他们已经出来了:

Batch

回答by Dipesh

Firebase now has Notifications inbuilt. https://firebase.google.com/docs/notifications/

Firebase 现在内置了通知。 https://firebase.google.com/docs/notifications/

回答by Abishek Gokal

I had the same problem and managed to figure out a solution a while back. I have detailed my solution in the following posts https://stackoverflow.com/a/44192515/7048719and https://stackoverflow.com/a/42240984/7048719

我遇到了同样的问题,不久前设法找到了解决方案。我在以下帖子中详细说明了我的解决方案https://stackoverflow.com/a/44192515/7048719https://stackoverflow.com/a/42240984/7048719

You have to create a firebase data service class and use a shared instance to hold the observers in memory when the app goes into background. From there it is just a matter doing what you wish.

您必须创建一个 firebase 数据服务类,并在应用程序进入后台时使用共享实例将观察者保存在内存中。从那里开始只是做你想做的事情。