标签: firebase-cloud-messaging

当应用程序被终止时,iOS 不会收到推送通知

我在 Stack Overflow 上发现了类似的问题,但没有一个能澄清这一点。

我正在使用 Firebase Cloud Messaging 在我的应用程序中发送推送通知。我将收到的消息存储在本地数据库中。当我的应用程序处于活动状态或在后台时,我的应用程序能够接收通知(正确调用委托方法),但如果应用程序被强制退出或不在内存中,则设备也会接收通知并位于通知中心但是当应用程序通过图标启动时,没有调用任何委托方法。如果用户单击通知中心中的“消息”,则会启动应用程序,但只会接收单击的消息,而不是所有消息(在收到多个通知的情况下)。据苹果公司称,如果用户强制退出,系统不会自动启动您的应用程序。在这种情况下,用户必须重新启动您的应用程序或重新启动设备,然后系统才会尝试再次自动启动您的应用程序

但即使用户启动应用程序仍然没有收到收到并位于通知中心的通知。

以下是该应用程序遵循的要点:

  • 我的应用程序没有 VoIP 功能。
  • 可用内容已设置为 1。
  • 已启用接收后台远程通知。
  • 所有发送的通知均已收到并显示在通知中心。

{
    aps =     {
        alert =         {
            body = "Push Notification Test Message";
            title = Push Notification;
        };
        badge = 1;
        "content-available" = 1;
        sound = default;
    };
    "gcm.message_id" = "0:1499340350307980%361a2e5b361a2e5b";
    m = "Push Notification Test Message";
    tag = m;
}
Run Code Online (Sandbox Code Playgroud)

objective-c push-notification apple-push-notifications ios firebase-cloud-messaging

2
推荐指数
1
解决办法
2183
查看次数

当没有互联网连接时使用 FCM 发送推送通知

我使用 Firebase Cloud Messaging (FCM) 向各种 Android 智能手机发送推送通知。当智能手机有互联网连接时,一切正常。但如果智能手机没有互联网连接,通知就会丢失。

我的问题是,有没有办法在智能手机恢复互联网连接时发送通知?

android push-notification firebase firebase-cloud-messaging

2
推荐指数
1
解决办法
6664
查看次数

Firebase iOS 11 按下按钮后请求用户通知

我正在使用 Firebase 在 iOS 11 上启用推送通知。我尝试仅在按下按钮后询问用户的通知权限。

目前,该应用程序在加载时立即请求用户许可。我想EnableNotificationViewController.swift在按下按钮后在课堂上请求此许可。

AppDelegate.swift

import UIKit
import Firebase
import FBSDKCoreKit
import UserNotifications
import FirebaseInstanceID
import FirebaseMessaging

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

        FirebaseApp.configure()

        // [START set_messaging_delegate]
        Messaging.messaging().delegate = self


        if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self

            let authOptions: UNAuthorizationOptions = …
Run Code Online (Sandbox Code Playgroud)

push-notification ios firebase firebase-cloud-messaging

2
推荐指数
1
解决办法
1659
查看次数

使用 Firebase Cloud Messaging 从服务器端管理主题订阅的示例 GET 请求

我在https://developers.google.com/instance-id/reference/server#get_information_about_app_instances找到以下示例 GET 请求:

https://iid.googleapis.com/iid/info/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA?details=trueAuthorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
Run Code Online (Sandbox Code Playgroud)

该示例中的关键是:AIzaSyZ-1u...0GBYzPu7Udno5aA。我在哪里可以找到我应该在 GET 请求中使用的密钥?我试图在https://console.developers.google.com/apis/credentials找到它,这就是我看到的:

在此输入图像描述

我尝试使用上图中看到的所有四个键,但我总是从浏览器收到此消息:

{"error":"MissingAuthorization"}
Run Code Online (Sandbox Code Playgroud)

这个错误是指密钥错误还是其他原因?我是否在正确的地方寻找钥匙?谢谢。

编辑1:我正在查看如何检查已订阅了多少主题?,我还尝试使用在 Firebase 控制台的“Cloud Messaing”选项卡下找到的密钥。这是我所看到的:

在此输入图像描述

我也尝试使用上图中的这些键进行 GET 请求,但仍然看到相同的错误:{"error":"MissingAuthorization"}

编辑2:我从命令行使用它:

C:\curl>curl -k https://iid.googleapis.com/iid/info/nKctODamlM4:CKrh_PC8kIb7O...clJONHoA?details=trueAuthorization:key=AIzaSyZ-1u...0GBYzPu7Udno5aA
{"error":"MissingAuthorization"}
C:\curl>
Run Code Online (Sandbox Code Playgroud)

请注意,我如何简单地复制/粘贴在“示例 GET 请求”标题下的https://developers.google.com/instance-id/reference/server#get_information_about_app_instances中找到的内容。我什至没有尝试使用自己的密钥,但我看到了相同的错误:{"error":"MissingAuthorization"}。这是否意味着问题出在我使用的密钥上?这不是我在 Firebase 控制台中看到的吗?

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

2
推荐指数
1
解决办法
2865
查看次数

如何处理 Firebase 通知,即 Android 中的通知消息和数据消息

当用户处于前台和后台时,使用 Xamarin Android 在 firebase 中处理通知消息和数据消息的最佳方法是什么?

另外,如何获取通知数据,例如特定通知的文本?

PS:我访问过以下线程,但没有一个真正有帮助:

当设备屏幕关闭时如何处理 firebase 通知?

Firebase 通知和数据

在 Android 托盘上显示 firebase 通知数据消息

xamarin.android firebase xamarin firebase-cloud-messaging

2
推荐指数
1
解决办法
3142
查看次数

通过条件将 Firebase 云消息传递 (FCM) 发送到多个主题的正确语法是什么

简而言之,我想使用 Google Cloud Functions 向订阅主题组合的设备发送通知。

\n\n

文档说:

\n\n
\n

“主题中的\'TopicA\' &&(主题中的\'TopicB\' || 主题中的\'TopicC\')”

\n
\n\n

我试图做的是:

\n\n
var topicsConditions = `\'${type}\' in topics && (\'${area}\' in topics || \'${city}\' in topics)`;\n\n// Send a message to devices subscribed to the provided topic.\nadmin.messaging().sendToCondition(topicsConditions, notificationPayload)\n  .then(function(response) {\n    // See the MessagingTopicResponse reference documentation for the\n    // contents of response.\n    console.log("Successfully sent message:", response);\n  })\n  .catch(function(error) {\n    console.log("Error sending message:", error);\n  });\n
Run Code Online (Sandbox Code Playgroud)\n\n

但我不断收到此错误:

\n\n
\n

发送消息时出错:{ 错误:提供的参数无效。原始服务器响应:“无效的“条件”字段:仅支持\'主题\'条件\n”。状态代码:400。\n 位于 FirebaseMessagingError.Error(本机)\n 位于 FirebaseMessagingError.FirebaseError [作为构造函数] (/user_code/node_modules/firebase-admin/lib/utils/error.js:39:28)\n …

node.js firebase google-cloud-functions firebase-cloud-messaging

2
推荐指数
1
解决办法
2653
查看次数

Java 使用 UTF-8 发送 http POST

我需要使用 Google FCM 发送 HTTP POST。通过下面的代码,可以发送英文消息,但可以发送中文字符。我通过到处添加 UTF-8 进行了多次尝试...需要帮助。

\n\n

我的消息的有效负载是下面代码中的 str2。\nAndroid APP 中显示的结果是 \nHello+%E6%88%91

\n\n

E68891是正确的UTF-8代码,但我需要它显示为汉字。

\n\n
package tryHttpPost2;\nimport java.io.DataOutputStream;\nimport java.net.URL;\nimport java.net.URLEncoder;\nimport javax.net.ssl.HttpsURLConnection;\n\npublic class TryHttpPost2 \n{\n    public static void main(String[] args) throws Exception {\n        String url = "https://fcm.googleapis.com/fcm/send";\n        URL obj = new URL(url);\n        HttpsURLConnection con = (HttpsURLConnection) obj.openConnection();\n        con.setRequestMethod("POST");\n        con.setRequestProperty("Content-Type", "application/json;x-www-form-urlencoded;charset=UTF-8");\n        con.setRequestProperty("Accept-Charset", "UTF-8");\n        con.setRequestProperty("Authorization", "key=...............");\n\n        String str1 = "{\\"to\\":\\"/topics/1\\",\\"notification\\":{\\"title\\":\\"";\n        String str2 = URLEncoder.encode("Hello \xe6\x88\x91", "utf-8");\n        String str3 = "\\"}}";\n        String urlParameters = str1+str2+str3;\n        con.setDoOutput(true);\n        DataOutputStream wr = new DataOutputStream(con.getOutputStream());\n\n        wr.writeBytes(urlParameters);\n …
Run Code Online (Sandbox Code Playgroud)

java post http firebase-cloud-messaging

2
推荐指数
1
解决办法
4634
查看次数

应用程序关闭时 Xamarin FCM 不工作

我在 Xamarin Android 中使用 Firebase 云消息传递进行远程通知,当应用程序位于前台和后台时,通知工作正常,但如果应用程序关闭,则通知不会到达。

我一步步按照Xamarin 教程进行操作。

任何想法?

xamarin.android xamarin firebase-cloud-messaging

2
推荐指数
1
解决办法
1445
查看次数

你可以为ios设置带有FCM通知的thread-id吗

Firebase FCM 消息支持tagAndroid,这会导致新通知用具有相同标记的旧通知替换前一个通知。有没有办法在ios上做同样的事情?

这个答案建议在数据有效负载中使用线程 ID。但这对我不起作用。

ios firebase google-cloud-messaging firebase-cloud-messaging cordova-plugin-fcm

2
推荐指数
1
解决办法
4938
查看次数

我应该如何将通知通道分配给现有的 Firebase 通知类?

使用 Firebase,我向我的应用程序发送通知,并通过通知数据的点击操作打开某些活动。问题是,它在 API 级别 <26 的情况下工作正常。但对于新版本,所有通知都必须分配给一个通道。但我不确定如何为现有系统分配适用于 API 级别 26 或更高级别的通道?

这是我的FirebaseMessagingServicejava类:

public class FirebaseMessagingService extends com.google.firebase.messaging.FirebaseMessagingService {
    private static final String TAG = "FirebaseMessagingServic";

    public FirebaseMessagingService() {}

    @Override
    public void onMessageReceived(RemoteMessage remoteMessage) {
        if (remoteMessage.getData().size() > 0) {
            Log.d(TAG, "Message data payload: " + remoteMessage.getData());
            try {
                JSONObject data = new JSONObject(remoteMessage.getData());
                String jsonMessage = data.getString("extra_information");
                Log.d(TAG, "onMessageReceived: \n" +
                    "Extra Information: " + jsonMessage);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        if (remoteMessage.getNotification() != null) { …
Run Code Online (Sandbox Code Playgroud)

notifications android firebase firebase-cloud-messaging

2
推荐指数
1
解决办法
4123
查看次数