【问题标题】:Flutter Push Notification TopicFlutter 推送通知主题
【发布时间】:2021-06-26 20:40:51
【问题描述】:

我的通知正常,但我添加了一个主题,现在我收到此错误

    Runner[1964:844150] [VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: PlatformException(Error 8, com.google.fcm, The operation couldn’t be completed. Cannot parse topic name: '/NEW'. Will not subscribe., null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159)
<asynchronous suspension>
2021-03-30 22:45:32.221182+0300 Runner[1964:844150] [VERBOSE-2:ui_dart_state.cc(177)] Unhandled Exception: PlatformException(Error 8, com.google.fcm, The operation couldn’t be completed. Cannot parse topic name: '/NEW'. Will not subscribe., null)
#0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:582)
#1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:159)
<asynchronous suspension>
2021-03-30 22:45:32.222853+0300 Runner[1964:844140] 6.33.0 - [Firebase/Messaging][I-FCM002009] Cannot parse topic name: '/NEW'. Will not subscribe.
2021-03-30 22:45:32.223594+0300 Runner[1964:844140] 6.33.0 - [Firebase/Messaging][I-FCM002009] Cannot parse topic name: '/NEW'. Will not subscribe.

这是我接收通知的代码:

class PushNotificationService {
  final FirebaseMessaging _fcm;

  PushNotificationService(this._fcm);

  Future initialise() async {
    if (Platform.isIOS) {
      _fcm.requestNotificationPermissions(IosNotificationSettings());
    }

    String token = await _fcm.getToken();
    
      _fcm.subscribeToTopic('/NEW');

    debugPrint("FirebaseMessaging token: $token");
    _fcm.configure(
      onMessage: (Map<String, dynamic> message) async {
        debugPrint("onMessage: $message");
      },
      onLaunch: (Map<String, dynamic> message) async {
        debugPrint("onLaunch: $message");
        _serialiseAndNavigate(message);
      },
      onResume: (Map<String, dynamic> message) async {
        debugPrint("onResume: $message");
        _serialiseAndNavigate(message);
      },
    );
  }

正如我上面所说,在我添加此行 _fcm.subscribeToTopic('/NEW'); 之前它工作正常,并且在 android 上它工作正常,我没有收到任何错误

【问题讨论】:

    标签: flutter push-notification


    【解决方案1】:

    您不能将'/NEW' 用作主题。错误说Cannot parse topic name: '/NEW'. Will not subscribe.

    尝试将其更改为'topics/new'。您应该在订阅频道之前添加topics/'

    【讨论】:

    • 这对我不起作用,但实际上只是使用NEW 作为订阅频道工作正常
    猜你喜欢
    • 2021-01-12
    • 2020-02-14
    • 2016-07-21
    • 2018-03-22
    • 2019-07-19
    • 2017-11-26
    • 1970-01-01
    • 2021-06-13
    • 2021-05-13
    相关资源
    最近更新 更多