我最近问了一个SO 问题,询问如何使用 Firebase 消息传递的主题向组中的每个人发送消息,除了触发通知的人(写入数据库中的组部分)。我得到了一个有趣的答案,它涉及为我的 iOS 应用程序的每个用户创建一个主题,然后使用为每个成员创建的主题向组中的每个成员发送一条消息。主题的名称只是该人的 uid,所以我只是遍历组成员的 uid 并向其相应的主题发送消息(忽略触发用户的 uid)。
使用该解决方案将意味着我的应用程序的每个用户都拥有自己的主题(/topics/<uid1>,/topics/<uid2>,等)。我想知道这样做是否有任何缺点。这将简化我发送消息的云功能,但我不确定拥有这么多主题在成本和性能方面是否昂贵。有人可以帮我弄清楚这是否是一个好的解决方案吗?
我正在尝试通过 Firebase 向某个客户端发送消息。这是我当前的(测试)代码:
import json
import requests
import urllib
def send_message():
server = "https://fcm.googleapis.com/fcm/send"
api_key = "xxx"
user_token = "xxx"
headers = {'Content-Type': 'application/json', 'Authorization': 'key=' + api_key}
data = {"type": "dataUpdate"}
payload = {"data": data, "to": user_token}
payload = json.dumps(payload)
res = requests.post(server, headers=headers, json=payload)
return res
Run Code Online (Sandbox Code Playgroud)
这会产生以下错误,由 Firebase 返回:
JSON_PARSING_ERROR: Unexpected token END OF FILE at position 0.
Run Code Online (Sandbox Code Playgroud)
发送到 Firebase 的以下 JSON 对我来说似乎是正确的:
{
"data": {
"type":"dataUpdate"
},
"to":"xxx"
}
Run Code Online (Sandbox Code Playgroud)
这是Firebase 文档中描述的格式。知道为什么 Firebase 不接受给定的数据吗?
我已经在 Xamarin Forms 中实现了 FCM 并且按预期工作。但是我想在收到新推送时从通知托盘中删除所有通知。
我曾尝试使用相同的collapse_key,但收到了所有消息,而不是最近推送的消息。
有人可以帮我弄这个吗?
谁能告诉我,当新用户注册我的应用程序时,如何在我的应用程序上收到带有他们的邮件 ID 和名称的通知?
例如,我是一个用户将注册的应用程序的开发人员,我将为自己制作一个应用程序,以便在何时以及有多少用户注册我的生产应用程序时收到通知我使用 Firebase 进行身份验证,谁能给我一些关于这个的想法?
android firebase firebase-authentication google-cloud-functions firebase-cloud-messaging
在下载之前如何从 Firebase 存储中获取文件大小?我想向用户显示文件大小,以便他们可以看到文件的确切大小。
我查找了https://firebase.google.com/docs/storage/android/download-files以检查是否有任何方法可以在下载之前获取特定文件的大小。但我没有发现任何有用的东西。
java android firebase firebase-realtime-database firebase-cloud-messaging
在我的应用程序中,我实现了 FCM 推送通知。当使用 FCM 控制台和 pushtry.com 网站检查通知时,它工作正常,然后我尝试使用实际的服务器 API,前台通知运行良好,但后台通知未收到,有时它很少收到,而且没有横幅和声音。请帮助找出问题。
在这里,我附上了我正在尝试的代码。
import UIKit
import UserNotifications
import Firebase
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
FirebaseApp.configure()
Messaging.messaging().delegate = self
if #available(iOS 10.0, *) {
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
return true …Run Code Online (Sandbox Code Playgroud) push-notification ios firebase swift firebase-cloud-messaging
很久以前,我在我的 Android 应用程序中使用了 GCM。它有一个缺点。当一条消息从 GCM 触发到我的 Android 应用程序时,如果设备未连接到互联网,则应用程序不会收到该消息。上线后也没有收到消息。FCM有同样的缺点吗?
我打算使用@angular/fire包装器在我的 Angular 应用程序中使用 Firebase 消息传递。
在最初的 Firebase 参考中,他们描述了一个firebase.messaging.isSupported() 方法,在计划让我的应用程序可用于各种浏览器时,这似乎是一个明智的调用。
现在@angular/fire 包装器没有公开该方法,并且在查看它的源代码时,它似乎也没有在内部使用它。
所以我的问题是:只注册requestToken@angular/fire 包装器的可观察对象是否安全,或者我是否需要首先确保当前浏览器支持 Firebase 消息传递?
Firebase API 从后端推送有效负载:
{
"registration_ids": [
"IKSiok9Zpip5cDcebQ67wc7TnpDuhMAFJm1xdGGI44s48JbXEu5iYa"
],
"notification": {
"body": "Push Test Facility Category",
"title": null,
"icon": "myicon",
"sound": "mySound",
"vibrate": 1,
"Badge": 1,
"click_action": "FCM_PLUGIN_ACTIVITY"
},
"data": {
"message": "Push Test Facility Category",
"title": null,
"b": "22",
"id": "2",
"category_name": "Restaurants",
"h": "1",
"p": 1,
"type": "2"
}
}
Run Code Online (Sandbox Code Playgroud)
fcm.service.ts
fcmListeners() {
this.firebase.onNotificationOpen().subscribe(async (data: any) => {
if (data.tap) {// when user tapped the background notification
} else { // Received in foreground
}
});
}
Run Code Online (Sandbox Code Playgroud)
你能告诉我为什么当我使用上述有效负载并且应用程序在后台时应用程序没有打开吗?这是 Android …
问题:我的 FCM 代码针对不同情况显示不同的消息:
案例 1:当应用程序运行时,它显示自定义通知正文
案例 2:当应用程序在后台运行时,它显示自定义通知正文
情况 3:当应用程序未运行时,它显示从 FCM 收到的默认消息而不是自定义消息
代码:
/* The class extends FirebaseMessagingService() */
override fun onMessageReceived(remoteMessage: RemoteMessage) {
try {
/* Some other codes */
val pendingIntent = PendingIntent.getActivity(this, 0, Intent(), PendingIntent.FLAG_ONE_SHOT)
val builder = NotificationCompat.Builder(this, "" + R.string.notification_channel_id)
.setSmallIcon(R.mipmap.ic_launcher_round)
.setContentTitle(remoteMessage.notification!!.title)
.setContentText(getString(R.string.custom_message_body))
.setAutoCancel(true)
.setContentIntent(pendingIntent)
val manager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
val channel = NotificationChannel("" + R.string.notification_channel_id, "Alert channel", NotificationManager.IMPORTANCE_DEFAULT)
manager.createNotificationChannel(channel)
}
manager.notify(0, builder.build())
/* super.onMessageReceived(remoteMessage) was REMOVED to prevent …Run Code Online (Sandbox Code Playgroud)