Firebase 刚刚发送测试消息

问题描述 投票:0回答:1

我正在将 Flutter 与 Firebase 结合使用,并且我使用的代码始终用于 Firebase 集成。

import 'dart:io';

import 'package:awesome_notifications/awesome_notifications.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';

class NotificationHelper {
  static void initFCM() async {
    final messaging = FirebaseMessaging.instance;
    // messaging.subscribeToTopic('push');

    await messaging.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false,
      sound: true,
    );

    AwesomeNotifications().initialize(
        null,
        [
          NotificationChannel(
              channelGroupKey: 'important_notification',
              channelKey: 'important_notification',
              channelName: 'Important Notification',
              channelDescription: 'Notification channel for important notifications',
              defaultColor: const Color(0xFFD9D9D9),
              importance: NotificationImportance.Max,
              ledColor: Colors.white)
        ],
        channelGroups: [
          NotificationChannelGroup(channelGroupKey: 'important-key', channelGroupName: 'important'),
        ]
    );

    FirebaseMessaging.onMessage.listen((RemoteMessage msg) {
      if (msg.notification != null) {
        handleNewNotification(msg.notification!);
      }
    });

    FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
  }
}

Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
  await Firebase.initializeApp();
  if(message.notification != null){
    // nedense backgroundda iken firebase in kendi notification ı çalışıyor
    // o yüzden buraya gitmeye gerek yok ne de olsa önceki notificationları kaydetmiyoruz.
    // handleNewNotification(message.notification!);
  }
}

handleNewNotification(RemoteNotification newNotification) {
  print(newNotification.body);
  if(Platform.isIOS) return;

  AwesomeNotifications().createNotification(
    content: NotificationContent(
        id: newNotification.hashCode,
        channelKey: 'important_notification',
        groupKey: 'important-key',
        title: newNotification.title,
        body: newNotification.body
    ),
  );
}

> Task :app:signingReport
Variant: debug
Config: debug
Store: /Users/oguz/.android/debug.keystore
Alias: AndroidDebugKey
MD5: BB:16:B9:CA:B3:18:09:E5:0D:D6:CA:75:9A:8A:80:4C
SHA1: F7:AE:1A:47:B4:38:E2:DB:18:11:7F:0A:08:41:AE:75:E8:4D:F8:D3
SHA-256: CC:CC:5B:C9:02:A7:22:B0:C3:80:AD:FB:28:5A:C6:EE:DE:7B:02:2D:A3:9B:8C:EB:C9:E5:A3:A3:E8:EC:0D:51
Valid until: 15 Eylül 2054 Salı
----------
Variant: release
Config: release
Store: /Users/oguz/Downloads/UploadingContentV2.0 2/kingburgerflutter/android/app/relese.jks
Alias: key0
MD5: 7F:44:CC:0D:F3:6F:7E:D7:1D:6D:FE:61:15:82:EE:AF
SHA1: 53:9F:A6:EA:B7:05:7C:3C:6F:B8:DB:2A:52:91:D6:1B:4B:3F:AD:C7
SHA-256: 58:45:29:AC:07:DB:0F:C0:4F:B1:CA:CD:41:24:33:55:C6:10:3E:0C:B3:33:9B:57:C4:2F:31:01:68:DF:36:46
Valid until: 20 Mayıs 2047 Pazartesi

Firebase android setup

fcm 1 fcm 2

图中显示的通知是我从测试通知中发送的通知。

当我第一次设置时,一切正常,我可以发送测试通知和常规通知。但是,现在常规通知不再到达设备。

我目前仅在 Android 上进行测试。

我尝试更改 google-services.json 文件、重新设置 FlutterFire、从 Firebase 控制台向主题发送通知并直接向应用程序发送通知、从 JavaScript 发送并检查 Google Cloud 中的日志。

Firebase Report

flutter firebase firebase-cloud-messaging
1个回答
0
投票

确保您使用“https://fcm.googleapis.com/v1/”API 发送通知,因为之前的“https://fcm.googleapis.com/fcm/send”端点已弃用且不再有效有效。

© www.soinside.com 2019 - 2024. All rights reserved.