标签: firebase-notifications

Firebase推送通知更新数据库

我正在尝试通过新的Firebase推送通知服务向我的用户发送一些数据.

我正在使用"消息文本" - "dbupdate"添加一些"键值"自定义数据项,以检测它是更新消息还是我要向用户显示的正常推送通知.

在我的接收器中,我检查我是否有自定义数据并运行更新,如果为真.如果不是这种情况,我会通过短信显示正常通知.

它仅在我的应用程序打开时有效.如果应用程序关闭,则无论如何都会显示通知,而我的if检查甚至没有运行,

一些代码:

public class PushMessageService extends FirebaseMessagingService {
    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        super.onMessageReceived(remoteMessage);
        Map<String,String> data = remoteMessage.getData();
        String link = data.get("link");
        String name = data.get("name");
        if (link!=null) {
            Log.d("link",link);
            Log.d("name",name);
            UpdateHelper.Go(this, link, name);
        }
        else {
            NotificationCompat.Builder mBuilder =
                    new NotificationCompat.Builder(this)
                            .setSmallIcon(R.drawable.ic_shop_white_24dp)
                            .setAutoCancel(true)
                    .setContentTitle(remoteMessage.getNotification().getTitle())
                   .setContentText(remoteMessage.getNotification().getBody());
            NotificationManager mNotificationManager =
                    (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
            mNotificationManager.notify(5, mBuilder.build());
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

这里举例说明

为什么会这样?即使应用程序关闭,我该怎么做才能运行我的代码?

android firebase firebase-notifications

6
推荐指数
1
解决办法
1万
查看次数

Firebase 云消息传递 - 响应 JSON 中的“成功”和“失败”

我使用 Firebase Cloud Messaging 向我的 Android 客户端应用程序发送通知,每个通知应根据其注册令牌发送到单个设备。

每次我通过https://fcm.googleapis.com/fcm/send发送通知时,我都会收到这样的 JSON 响应:

{
  "multicast_id": 108,
  "success": 1,
  "failure": 0,
  "canonical_ids": 0,
  "results": [
    { "message_id": "1:08" }
  ]
}
Run Code Online (Sandbox Code Playgroud)

我发现successfailure多余的 - 它们不是同一件事吗?我应该检查他们两个以确保一切正常吗?总是这样success != failure吗?

android json firebase firebase-cloud-messaging firebase-notifications

6
推荐指数
1
解决办法
7542
查看次数

Firebase Cloud Messaging - 向所有用户发送消息

我是 Firebase 云消息的新手。我构建了一个 IOS 应用程序来接收推送通知。该应用程序运行良好。我从 Firebase 控制台发送消息,并且它们显示正确。

现在我正在尝试构建一个 Web api 以允许我的客户发送推送消息(无需访问 firebase 控制台)。研究这里的文档我意识到我总是有一个“to”,意思是组、主题或设备 ID。

我的问题是:我可以向所有设备发送消息(就像我可以在控制台中执行的那样)吗?我是啊,怎么会这样呢?

提前致谢!

ios firebase firebase-cloud-messaging firebase-notifications

6
推荐指数
1
解决办法
5440
查看次数

如何处理来自系统托盘的通知

我知道在后台应用中处理消息

当您的应用在后台时,Android会将通知消息定向到系统托盘.用户点按通知会默认打开应用启动器.

这包括包含通知和数据有效负载的消息.在这些情况下,通知将传递到设备的系统托盘,并且数据有效负载将在启动器活动的附加内容中传递.

但我的应用程序应该检测通知何时到达进行操作(从服务器获取数据),因为当通知到达时必须加载数据但是,当应用程序在后台我不知道通知到达用户点击通知将打开应用程序并且我将加载数据,但是某些用户没有点击通知所以数据没有加载

所以我的问题任何方式知道什么时候应用程序在后台的案例应用程序接收通知?

android android-notifications firebase-notifications

6
推荐指数
1
解决办法
1341
查看次数

如何使用swift 3发送带有firebase推送通知的图像

任何人都可以帮我发送这样的通知:

图像通知

我正在使用Firebase通知.我发送通知时,我尝试将图片网址设置为高级选项和键1的值.图像URL显示在调试器中,但当我的设备中出现通知时,不会显示图像.

这是我的代码.

import UIKit
import UserNotifications
import Firebase
import FirebaseInstanceID
import FirebaseMessaging

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?
let gcmMessageIDKey = "gcm.message_id"

func application(_ application: UIApplication,
                 didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    // Register for remote notifications. This shows a permission dialog on first run, to
    // show the dialog at a more appropriate time move this registration accordingly.
    // [START register_for_notifications]
    if #available(iOS 10.0, *) {
        let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
        UNUserNotificationCenter.current().requestAuthorization( …
Run Code Online (Sandbox Code Playgroud)

ios firebase swift3 firebase-cloud-messaging firebase-notifications

6
推荐指数
0
解决办法
4722
查看次数

如何检测令牌是否已过期或未在应用服务器上注册 Firebase FCM 通知?

我正在使用以下代码将 FCM 通知从服务器发送到设备:

    String fcmServerKey = externalConfig.getFcmServerKey();
            CloseableHttpClient httpclient = HttpClients.createDefault();
            HttpPost httpPost = new HttpPost(HTTPS_FCM_GOOGLEAPIS_COM_FCM_SEND);

            httpPost.setEntity(new StringEntity(message, ContentType.create("application/json")));
            httpPost.setHeader("Authorization", "key=" + fcmServerKey);

CloseableHttpResponse closeableHttpResponse= httpclient.execute(httpPost);
Run Code Online (Sandbox Code Playgroud)

在上面的代码中,当我获得响应对象时closeableHttpResponse,如何检测用于发送此请求的 fcm 令牌是否已过期或未注册?

从 firebase 应用程序仪表板中时,我尝试使用其 fcm 令牌将通知发送到设备,并且在从设备中删除应用程序后,我Failed在 firebase 仪表板上看到,将光标悬停在Failed我看到的 上Unregistered registration token

如何检测Unregistered registration token来自 api 响应对象的上述错误情况closeableHttpResponse

android push-notification firebase firebase-cloud-messaging firebase-notifications

6
推荐指数
2
解决办法
5606
查看次数

适用于Android的Google Analytics.接收通知的用户被视为活动用户

我在我的应用中使用了Google Analytics(分析),而且工作正常.但是,如果我每天有100个活跃用户,然后我发送通知,则我将1000个连接用户的峰值计为"活动".

我不知道是否有一种简单的方法可以防止这些用户被视为活动用户.他们中的大多数人不会打开通知,我不希望他们算作活动.我想只计算打开应用程序的用户,而不是所有收到通知的用户.

我在发送的通知中使用"body"字段,并在应用程序中创建自定义通知.

是否可以删除这些"活跃"用户?

非常感谢你!

android google-analytics firebase firebase-notifications

6
推荐指数
1
解决办法
455
查看次数

react-native-firebase getInitialNotification 循环

我使用 React Native Firebase 在 React Native 中接收通知。当在后台收到消息并单击通知时,将触发 getInitialNotification。如果我导航到另一个屏幕而不是回到我的 HomeActivity,getInitialNotification 将再次被触发。我怎样才能实现只触发一次?

import React, { Component } from 'react';
import { StyleSheet, Platform, View, Text, YellowBox, Button } from 'react-native';
import StyleIndex from './css/StyleIndex';

import firebase from 'react-native-firebase';
import type { Notification, NotificationOpen } from 'react-native-firebase';


export default class HomeActivity extends Component {
  state = { currentUser: null }

componentDidMount() {
    const { currentUser } = firebase.auth()
    this.setState({ currentUser })

    var collectionReference = firebase.firestore().collection('users');
    var query = collectionReference.where("phone", "==", currentUser.phoneNumber);
    // …
Run Code Online (Sandbox Code Playgroud)

javascript firebase react-native firebase-cloud-messaging firebase-notifications

6
推荐指数
1
解决办法
2801
查看次数

Firebase FCM 通知添加操作按钮

如何添加操作按钮来推送这样的通知: 在此处输入图片说明 我试过这个,但它不起作用:

=> https://firebase.googleblog.com/2018/05/web-notifications-api-support-now.html

这是我的通知负载:

array
(
    "title" =>  "FCM Message",
    "body" => "This is an FCM Message",
    "click_action" => "http://example.com/",
    "icon" => "/logo.jpg",
    "actions" => array(
        0 => array(
            'title' => 'Like',
            'click_action' => 'http://example.com/?aaa=1',
            'icon' => 'icons/heart.png',
        ),
        1 => array(
            'title' => 'Unsubscribe',
            'click_action' => 'http://example.com/?aaa=2',
            'icon' => 'icons/cross.png',
        ),
    ),
);
Run Code Online (Sandbox Code Playgroud)

我尝试使用消息有效负载也不起作用:

$msg = array
(
    "webpush" =>  array
    (
        "notification" =>  array
        (
            "title" =>  "Fish Photos ",
            "body" =>  "Thanks for signing up for …
Run Code Online (Sandbox Code Playgroud)

web-push firebase-cloud-messaging firebase-notifications

6
推荐指数
1
解决办法
8303
查看次数

Firebase通知的打开率未在控制台上计算

对于所有通知,未在控制台上计算打开的Firebase通知率.

在此输入图像描述

在少数论坛中,建议等待48小时才能获得分析,但在我们的案例中,打开通知的分析没有反映出来.

我们已经包含了两个:在gradle中编译'com.google.firebase:firebase-core:9.4.0'编译'com.google.firebase:firebase-messaging:9.4.0'.

firebase firebase-cloud-messaging firebase-analytics firebase-notifications

5
推荐指数
0
解决办法
529
查看次数