【问题标题】:Push Notification received but not displayed (Flutter / Dart)收到推送通知但未显示(Flutter / Dart)
【发布时间】:2020-08-05 08:24:31
【问题描述】:

json 中的通知被电话接收器很好地接收,并且在“onMessage”中有一个带有 json 内容的打印。但是,屏幕上不显示任何通知。这是发送的json代码:

    var client = http.Client();

    var jsonData = json.encode({
                "to": "/topics/$userId",
                "notification": {
                  "body": "$notificationText",
                  "title": "Title",
                },
                "data": {
                  "click_action": "FLUTTER_NOTIFICATION_CLICK",
                  "sound": "default",
                  "status": "done",
                  "screen": "ListPostsScreen",
                },
                "content_available": true,
                "priority": "high",
              });

              var headers = {
                'Authorization': "key=$key",
                'Content-Type': 'application/json',
              };

    var response = await client.post(url, headers: headers, body: jsonData);

    print(response.body);

主屏幕中的firebaseMessaging:

final FirebaseMessaging firebaseMessaging = FirebaseMessaging();
    firebaseMessaging.configure(
      onMessage: (Map<String, dynamic> message) async {
        print("onMessage: $message");
      },
      onLaunch: (Map<String, dynamic> message) async {
        print("onLaunch: $message");
      },
      onBackgroundMessage: Platform.isIOS ? null : myBackgroundMessageHandler,
      onResume: (Map<String, dynamic> message) async {
        print("onResume: $message");
      },
    );

这是 main/AndroidManifest.xml 中的意图过滤器

<intent-filter>
  <action android:name="FLUTTER_NOTIFICATION_CLICK" />
  <category android:name="android.intent.category.DEFAULT" />
</intent-filter>

我的 pubspec.yaml 包:

  firebase_messaging: ^5.1.6

我错过了什么吗? 谢谢。

【问题讨论】:

  • 你用什么来发送通知?并接收它们?你在使用任何包吗?
  • 我使用 firebase 云消息传递:firebase_core: ^0.4.0+9, firebase_analytics: ^5.0.2, firebase_auth: ^0.14.0+5; firebase_messaging:^5.1.6,
  • 应用崩溃时您看到的消息是什么?
  • 它说应用程序停止工作。你认为我可以在控制台中看到错误消息,在收到通知的手机上吗?当我进行测试时,只有发送通知的手机在 USB 中,所以我没有在另一边看到错误消息
  • 尝试连接死机的手机,看看死机时的错误是什么。也许它与通知无关。

标签: flutter dart push-notification notifications firebase-cloud-messaging


【解决方案1】:

这有点愚蠢,但我遇到了同样的问题,并意识到我的 请勿打扰 已打开。不过我什么都没想到,因为我把它关掉了。

但是,我猜是因为它按计划进行,它仍然会阻止通知。我现在让它们在输入时正常工作 - 在后台显示的 iOS 13.5 上。


资源

https://fireship.io/lessons/flutter-push-notifications-fcm-guide/

https://pub.dev/packages/firebase_messaging

https://github.com/fireship-io/192-flutter-fcm-push-notifications/blob/master/lib/main.dart

【讨论】:

    猜你喜欢
    • 2019-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-06
    • 2011-08-23
    相关资源
    最近更新 更多