0

I implemented FlutterFire Messaging with the subscribeToTopic method, as the snippet below:

final _topics = ['topicName'];

Future<void> subscribeTopics() async {
  for (final topic in _topics) {
    await FirebaseMessaging.instance.subscribeToTopic(topic);
  }
}

Future<void> unsubscribeTopics() async {
  for (final topic in _topics) {
    await FirebaseMessaging.instance.unsubscribeFromTopic(topic);
  }
}

And everything is fine in debug mode, but in my Crashlytics I'm receiving some reports about it (iOS only):

  • [firebase_messaging/unknown] The request timed out
  • [firebase_messaging/unknown] An unknown error has occurred
  • [firebase_messaging/unknown] A data connection is not currently allowed
  • [firebase_messaging/unknown] The Internet connection appears to be offline

All the errors appears to be about internet connection, so my question is: "Should I validate the user connection before use FCM or the lib is ready to deal with it but only in Android?"

Crashlytics Stacktrace

Non-fatal Exception: FlutterError
0  ???                            0x0 MethodChannelFirebaseMessaging.subscribeToTopic + 368 (method_channel_messaging.dart:368)
1  ???                            0x0 Messaging.subscribeTopics + 40 (messaging.dart:40)
2  ???                            0x0 Messaging.observeMessaging + 22 (messaging.dart:22)
3
  • 1
    You should disable App if there is no internet since it depends on it. check pub.dev/packages/connectivity_plus Commented Nov 5, 2021 at 3:24
  • Thanks, but you know if it is documented anywhere? Commented Nov 8, 2021 at 18:26
  • 1
    but there is no logic to use it without internet, right. Something like Connection Lost alert would be great Commented Nov 8, 2021 at 18:29

1 Answer 1

1

It's a general error so you shouldn't worry about it. When the internet connection restores the method will hopefully restart itself. You should also consider the case that It might generate an error while the app is in the background.

You can use try catch block to avoid these messages in your crashlytics dashboard.

final _topics = ['topicName'];

Future<void> subscribeTopics() async {
  try {
    for (final topic in _topics) {
      await FirebaseMessaging.instance.subscribeToTopic(topic);
    }
  } on FirebaseException {
    // do nothing
  }
}

Future<void> unsubscribeTopics() async {
  try {
    for (final topic in _topics) {
      await FirebaseMessaging.instance.unsubscribeFromTopic(topic);
    }
  } on FirebaseException {
    // do nothing
  }
}

Note It will also ignore all other error messages too. In that case You can handle it otherwise

final _topics = ['topicName'];

Future<void> subscribeTopics() async {
  try {
    for (final topic in _topics) {
      await FirebaseMessaging.instance.subscribeToTopic(topic);
    }
  } on FirebaseException catch (e) {
    if (e.code == 'unknown') {
      // do nothing
    } else {
      // do something
    }
  }
}

Future<void> unsubscribeTopics() async {
  try {
    for (final topic in _topics) {
      await FirebaseMessaging.instance.unsubscribeFromTopic(topic);
    }
  } on FirebaseException catch (e) {
    if (e.code == 'unknown') {
      // do nothing
    } else {
      // do something
    }
  }
}
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.