更新:谷歌错误报告描述
(正如谷歌开发倡导者在对答案 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
当用户注册到应用程序时,我想在我的android app用户的数据库表中存储FCM令牌.当我想向特定用户发送通知时,我将从相应的行获取令牌并发送推送通知.但我很困惑,每当应用程序用户从他的应用程序注销并从同一设备注册新帐户,那么将有两行因此数据库上同一设备的两个令牌.如何处理这种情况?设备中的旧令牌会发生什么?请有人可以帮帮我吗?
mysql android push-notification firebase firebase-cloud-messaging
我正在为Android开发一个聊天应用程序.我已经阅读了几周关于XMPP和Google Cloud Messaging(以及Firebase云消息传递)的内容,我仍然感到非常困惑.
目前,我已经在本地设置了一个XMPP服务器(Ejabberd)并使用Smack库成功地将我的Android应用程序连接到它.
根据我的理解,我需要使用GCM或更新的FCM进行推送通知,因此我已经在Google Cloud Platform中创建了一个项目.我的Android应用程序也可以使用Smack库连接到它(而不是直接连接到我的XMPP服务器).在我的服务器中,我有一个小型Java应用程序,它也使用Smack库连接到GCM.
一切都很好,直到这里.我最大的困惑是:如何将我的XMPP服务器与GCM一起用于推送通知?我在服务器端实现中找到的每个文档,示例,指南和教程都告诉我如何连接到GCM,但没有人告诉我如何将我的XMPP服务器与GCM结合使用.我错过了什么?我的Java应用程序只是连接到GCM,从GCM接收和发送消息,但我的XMPP服务器只是坐在那里什么都不做.实际上我的Android App和服务器Java App只使用GCM,而不是我的XMPP服务器.
我希望有人可以帮助我理解这一点,我显然缺少实现这一实现的一些关键要素.
java android xmpp google-cloud-messaging firebase-cloud-messaging
我使用下面的脚本向特定用户发送通知:
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'My_API_KEY' );
$registrationIds = array( TOKENS );
// prep the bundle
$msg = array
(
'body' => "abc",
'title' => "Hello from Api",
'vibrate' => 1,
'sound' => 1,
);
$fields = array
(
'registration_ids' => $registrationIds,
'notification' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( …Run Code Online (Sandbox Code Playgroud) 由于新的后台执行限制,我们的应用程序在Android O上崩溃.我们使用的是Firebase版本10.2.1,它是添加了Android O支持的版本.
好像是Firebase的一个问题?或者是否需要进行一些改变才能支持这一点?
java.lang.IllegalStateException: Not allowed to start service Intent { act=com.google.firebase.INSTANCE_ID_EVENT pkg=my.package.name cmp=my.package.name/my.package.name.MyFcmIdService (has extras) }: app is in background uid UidRecord{30558fa u0a327 RCVR idle procs:1 seq(0,0,0)}
at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1505)
at android.app.ContextImpl.startService(ContextImpl.java:1461)
at android.content.ContextWrapper.startService(ContextWrapper.java:644)
at android.support.v4.content.WakefulBroadcastReceiver.startWakefulService(WakefulBroadcastReceiver.java:99)
at com.google.firebase.iid.zzg.b(zzg.java:9)
at com.google.firebase.iid.zzg.a(zzg.java:72)
at com.google.firebase.iid.zzg.a(zzg.java:2)
at com.google.firebase.iid.FirebaseInstanceIdService.a(FirebaseInstanceIdService.java:23)
at com.google.firebase.iid.FirebaseInstanceIdService.a(FirebaseInstanceIdService.java:34)
at com.google.firebase.iid.FirebaseInstanceId.<init>(FirebaseInstanceId.java:31)
at com.google.firebase.iid.FirebaseInstanceId.getInstance(FirebaseInstanceId.java:47)
at com.google.firebase.iid.FirebaseInstanceId.a(FirebaseInstanceId.java:4)
at com.google.firebase.iid.FirebaseInstanceIdService.a(FirebaseInstanceIdService.java:19)
at com.google.firebase.iid.FirebaseInstanceIdService.b(FirebaseInstanceIdService.java:35)
at com.google.firebase.iid.zzb$zza$1.run(zzb.java:24)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
at java.lang.Thread.run(Thread.java:764)
Run Code Online (Sandbox Code Playgroud)
更新升级到11.4.2可以解决此问题.
我正在构建一个可以接收推送通知的Android应用.我已经安装了Firebase云消息传递并且非常有效,因此我可以将以下有效负载发送到有效令牌并接收通知和数据.
使用网址 https://fcm.googleapis.com/fcm/send
{
"to":"<valid-token>",
"notification":{"body":"BODY TEXT","title":"TITLE TEXT","sound":"default"},
"data":{"message":"This is some data"}
}
Run Code Online (Sandbox Code Playgroud)
我的应用程序正确接收它并可以处理它.
唯一的轻微皱纹是我在调试中抛出以下异常:
Error while parsing timestamp in GCM event
java.lang.NumberFormatException: Invalid int: "null"
at java.lang.Integer.invalidInt(Integer.java:138)
...
Run Code Online (Sandbox Code Playgroud)
它不会崩溃应用程序,它只是看起来不整洁.
我已经尝试将一个timestamp项目添加到主要有效负载,通知,数据,还尝试了变种,time但似乎无法摆脱异常(和我可能谷歌,我找不到答案) .
如何通过时间戳让它停止抱怨?
编辑:这是我的onMessageReceived方法,但我认为异常在它到达之前抛出
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
//TODO Handle the data
}
// Check if message …Run Code Online (Sandbox Code Playgroud) android timestamp push-notification firebase firebase-cloud-messaging
在 node-js 中运行以下行后:
import * as admin from "firebase-admin";
import * as serviceAccount from "../../firebase_service_account_key.json";
const app = admin.initializeApp({
credential: admin.credential.cert(serviceAccount as any),
databaseURL: "https://my-app-path.firebaseio.com"
});
admin.messaging().send({
token: "known-good-token",
notification: {
title: "Test Push Note",
body: "Here is some text"
}
});
Run Code Online (Sandbox Code Playgroud)
我收到错误:
Error: Auth error from APNS or Web Push Service
Raw server response:
"{
"error":{
"code":401,
"message":"Auth error from APNS or Web Push Service",
"status":"UNAUTHENTICATED",
"details"[
{
"@type":"type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode":"THIRD_PARTY_AUTH_ERROR"
},
{
"@type":"type.googleapis.com/google.firebase.fcm.v1.ApnsError",
"statusCode":403,
"reason":"InvalidProviderToken"
}
]
}
}" …Run Code Online (Sandbox Code Playgroud) 我想在 Flutter 中处理 FCM 的后台消息,但是当 fcm 在后台模式下向应用程序发送消息并在日志中出错时出现错误
pubspec.yaml:
firebase_core: ^0.7.0
firebase_messaging: ^8.0.0-dev.14
Run Code Online (Sandbox Code Playgroud)
主活动.kt :
package com.mydomain.myproject
import io.flutter.embedding.android.FlutterActivity
class MainActivity: FlutterActivity() {
}
Run Code Online (Sandbox Code Playgroud)
应用程序.kt :
package com.mydomain.myproject
import com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin
import io.flutter.app.FlutterApplication
import io.flutter.plugin.common.PluginRegistry
import io.flutter.plugin.common.PluginRegistry.PluginRegistrantCallback
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundExecutor
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingBackgroundService
import io.flutter.plugins.firebase.messaging.FlutterFirebaseMessagingPlugin
import io.flutter.plugins.pathprovider.PathProviderPlugin
class MyApplication : FlutterApplication(), PluginRegistrantCallback {
override
fun onCreate() {
super.onCreate()
FlutterFirebaseMessagingBackgroundService.setPluginRegistrant(this)
FlutterFirebaseMessagingBackgroundExecutor.setPluginRegistrant(this)
}
override
fun registerWith(registry: PluginRegistry) {
PathProviderPlugin.registerWith(registry.registrarFor("io.flutter.plugins.pathprovider.PathProviderPlugin"))
FlutterLocalNotificationsPlugin.registerWith(registry.registrarFor("com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin"))
FlutterFirebaseMessagingPlugin.registerWith(registry.registrarFor("plugins.flutter.io/firebase_messaging"))
}
}
Run Code Online (Sandbox Code Playgroud)
使用fcm的代码: 我只是在主应用程序类的initState()中调用了_initFcm()。我的目标是当应用程序在后台时,后台 fcm 方法必须触发,我必须在首选项中保存消息数据,以便在应用程序打开时做一些事情
void _initFcm() {
Firebase.initializeApp();
FirebaseMessaging.onMessageOpenedApp.listen((message) {
Logger.log("_messaging onMessageOpenedApp: ${message}"); …Run Code Online (Sandbox Code Playgroud) firebase flutter firebase-cloud-messaging flutter-method-channel
我正在尝试处理启动选项并在点击我在swift 3中收到的远程通知时打开一个特定的视图控制器.我已经看到类似的问题,例如这里,但没有新的swift 3实现.我看到了一个类似的问题(和)在AppDelegate.swift中我在didFinishLaunchingWithOptions中有以下内容:
var localNotif = (launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as! String)
if localNotif {
var itemName = (localNotif.userInfo!["aps"] as! String)
print("Custom: \(itemName)")
}
else {
print("//////////////////////////")
}
Run Code Online (Sandbox Code Playgroud)
但是Xcode给了我这个错误:
Type '[NSObject: AnyObject]?' has no subscript members
Run Code Online (Sandbox Code Playgroud)
我也试过这个:
if let launchOptions = launchOptions {
var notificationPayload: NSDictionary = launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] as NSDictionary!
}
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
error: ambiguous reference to member 'subscript'
Run Code Online (Sandbox Code Playgroud)
我有类似的错误,无论我以前使用类似的代码通过键从字典中获取值,我不得不替换代码,基本上安全地首先解开字典.但这似乎不适用于此.任何帮助,将不胜感激.谢谢.
ios firebase swift firebase-cloud-messaging firebase-notifications