有没有办法FCM从node.js服务器发送通知?
我在文档中没有找到任何关于它的内容.
有没有办法通过FCM从一台Android设备向与Firebase数据库连接的其他设备发送上游通知消息.
我知道XMPP服务器然后可以接收上游消息并将通知发送到其他设备.要接收与上游API一起发送的消息,我需要实现XMPP服务器,但还有其他方法吗?
我们使用FCM为iOS和Android发送远程通知.以下是我们从后端发送的有效负载.
options = {
notification: {
title: "title",
body: body,
sound: 'default'
},
priority: "high",
content_available: true,
data: {
type: 'type',
id: id,
}
}
Run Code Online (Sandbox Code Playgroud)
这适用于ios和android.但由于某种原因,android方面我们需要发送title,body并且sound对于data有效负载中的密钥而言需要删除notification有效负载.
现在,当应用程序未处于活动状态时,通知未收到ios端,横幅通知未到达但数据在应用处于活动状态时正在接收.我们在iOS方面需要横幅广告.
这个notification关键是banner在iOS中显示的mandetory 吗?
如何为iOS和Android使用相同的有效负载.
options = {
priority: "high",
content_available: true,
data: {
title: "title",
body: body,
sound: 'default'
type: 'type',
id: id,
}
}
Run Code Online (Sandbox Code Playgroud)
还尝试添加各种组合content_available和priority键.通过所有FCM文档,它仍然混淆.帮助/建议表示赞赏.
我们的应用程序现在有 targetSdkVersion 26 ( Android 8 ) 并且应用程序使用 FCM 推送通知。当应用程序处于前台状态时,推送通知运行良好。当应用程序不在前台状态时单击通知时会出现此问题。我刚刚在清单中添加了元数据,但仍然出现相同的错误。
AndroidManifest.xml
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel"
android:value="@string/default_notification_channel_id"/>
Run Code Online (Sandbox Code Playgroud)
MyFirebaseMessagingService.java
/**
* Create and show a simple notification containing the received FCM message.
*/
private void sendNotification(NotificationModel notificationModel)
{
Intent intent;
if (notificationModel.getAppLink() != null)
{
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(notificationModel.getAppLink()));
} else
{
intent = new Intent(this, NoticeActivity.class);
}
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent,
PendingIntent.FLAG_ONE_SHOT);
Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
if (notificationModel.getAppLink() != null) …Run Code Online (Sandbox Code Playgroud) push-notification android-notifications firebase-cloud-messaging android-studio-3.0 android-8.0-oreo
我正在尝试使用Firebase来处理推送通知.我安装了Firebasepod('Firebase/Core'和'FirebaseMessaging'pods).
在我将Firebase导入项目之后
import Firebase
Run Code Online (Sandbox Code Playgroud)
我已经像这样配置了Firebase应用程序(代码是从官方文档中复制的):
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
-> Bool {FIRApp.configure() }
Run Code Online (Sandbox Code Playgroud)
之后,我尝试使用此代码(代码从官方文档复制):
if #available(iOS 10.0, *) {
let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_,_ in })
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
// For iOS 10 data message (sent via FCM)
FIRMessaging.messaging().remoteMessageDelegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
Run Code Online (Sandbox Code Playgroud)
但是我从标题中得到了错误: …
apple-push-notifications ios firebase swift firebase-cloud-messaging
我使用Firebase作为后端.我还使用FCM作为Firebase提供的功能之一.FCM在iOS 10中运行良好,但在切换到iOS 11后,推送通知停止进入用户设备,我自己没有收到任何从云功能或Firebase控制台中的通知部分发送的推送通知.如何解决这个问题?
更新:我从Firebase Notifcations发送了几个推送通知,但它们没有来.
// MARK: - Push notification
extension AppDelegate: UNUserNotificationCenterDelegate {
func registerPushNotification(_ application: UIApplication) {
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_, _ in })
// For iOS 10 data message (sent via FCM)
Messaging.messaging().delegate = self
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
//When the notifications of this code worked well, there was not yet. …Run Code Online (Sandbox Code Playgroud) push-notification ios firebase firebase-cloud-messaging ios11
当设备未注册(应用程序已卸载)时,FCM HTTP v1 API应返回错误代码"UNREGISTERED".但是,API返回404"未找到请求的实体".
有没有人经历过这个?这是预期的吗?在文档中的任何地方都没有提到这一点.
当404错误并收到"未找到请求的实体"消息时,假设设备未注册是否安全?
以下是收到的错误的全部内容.
{
"error": {
"code": 404,
"message": "Requested entity was not found.",
"errors": [
{
"message": "Requested entity was not found.",
"domain": "global",
"reason": "notFound"
}
],
"status": "NOT_FOUND"
}
}
Run Code Online (Sandbox Code Playgroud)
例外:
Caused by: com.google.firebase.messaging.FirebaseMessagingException: Requested entity was not found.
at com.google.firebase.messaging.FirebaseMessaging.handleSendHttpError(FirebaseMessaging.java:266) ~[firebase-admin-5.9.0.jar:?]
Run Code Online (Sandbox Code Playgroud)
有关参考API文档:
https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode
更新:谷歌错误报告描述
(正如谷歌开发倡导者在对答案 1 的评论中所建议的那样,提交了一份错误报告;更新这里的内容,因为它更简洁、更准确地描述了问题)
我不需要或不想向我的用户显示任何通知。许多用户不愿意给予通知权限,因为他们认为他们会开始看到通知。
但我希望将数据从服务器推送到我的网页。该网页处于活动状态并位于前台。这是 Web Sockets 设计用于的经典用例。
我知道我可以编写自己的 Web 套接字服务器并以某种方式尝试扩展它,或者去其他第三方寻求外包的可扩展 Web 套接字推送解决方案。
但是,这不是 Firebase 消息传递所针对的消息传递的一个非常常见的“子用例”吗?因此谷歌不应该支持这个用例吗?我看不到任何基本的技术障碍,但由于谷歌如此聪明,如果我遗漏了为什么不能或不应该这样做的原因,请赐教。
原始 StackOverflow 问题文本:
我不需要后台通知或服务人员。我想要的只是在当前加载并在前台将数据发送到网页。
Websockets 不需要任何许可,但它们需要一个 websocket 服务器和维护。扩展它是困难的或昂贵的。
Firebase 从根本上解决了这个问题,但我不明白为什么它必须要求用户给予通知权限,即使我只想在页面加载时推送数据;不在后台。
我正在尝试将 Google 的 Firebase Cloud Messaging (FCM) 实施到我的 Nuxt.js APP 中。
到目前为止,我已经安装了 firebase,在 ./plugins 文件夹中创建了一个 firebase.js 插件,导入并初始化了 firebase 和消息传递服务,一切似乎都运行良好。
现在我不知道如何或从这里去哪里..
这个想法是在通知模块中处理 vuex 中的所有内容。
我想同时处理后台和前台通知。后台由 service-worker 处理,对于前台,我制作了一个简单的通知组件,我想在每次收到来自 FCM 的推送通知时显示该组件。
问题:
我将如何注册 Service Worker、请求许可和处理前台/后台通知?我的意思是特定于 Nuxt.js 的确切位置/文件/方式?我应该为此制作另一个插件,使用中间件文件夹还是只处理默认布局文件中的所有内容?
最干净的方法是什么?
提前致谢!
javascript vue.js service-worker firebase-cloud-messaging nuxt.js