Flutter Push Notification Topic

Viewed 236

My notification were working but I added a topic and now I get this error

    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.

And this is my code for receiving notifications:

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);
      },
    );
  }

As I said above it worked before I added this line _fcm.subscribeToTopic('/NEW'); and on android it works fine, I get no errors

1 Answers

You can't use '/NEW' AS a topic. The error says Cannot parse topic name: '/NEW'. Will not subscribe.

Try changing it to 'topics/new'. You should include topics/' before your subscription channels.

Related