DinoLeung / TeleDart

A Dart library interfacing with the latest Telegram Bot API.
https://pub.dev/packages/teledart
GNU General Public License v3.0
314 stars 69 forks source link

I'm having issue with teledart.onMessage(entityType: '*').listen((message) is not executing when running as Release and the app is in Background state for iOS #269

Open sotheavuthnguon opened 7 months ago

sotheavuthnguon commented 7 months ago

Describe the bug



void teledartStartListening(TeleDart teledart) async { teledart.onMessage(entityType: '*').listen((message) async { debugPrint('Received message => ${message.text}'); final textMessage = message.text; if (textMessage?.compareTo("111111") == 0) { teledart.stop();

  message.reply("Congratulations", parseMode: "HTML");
  // After verify OTP on telegram success we need to call to make update to back-end server.
} else {
  if (textMessage == "" &&
      message.from != null &&
      message.from?.isBot == true &&
      (message.chat.type.toUpperCase() == "group".toUpperCase() ||
          message.chat.type.toUpperCase() == "supergroup".toUpperCase())) {
    message.reply("Hello", parseMode: "HTML");
  } else {
    message.reply("Hello", parseMode: "HTML");
  }
}

}); }



I cannot receive the messages when running as **Release** and the app is in **Background** state, but when running as Debug, I can receive the messages as normal.

## Expected behavior
I would like the behavior that we can still receiving messages in Telegram when running as **Release** and the app is in **Background** state. Thanks.
DinoLeung commented 6 months ago

Not a iOS expert here, would be good if someone can contribute to this issue. My understanding is that the teledart stuff need to be run in the background thread, so the instance will not be destroy once the on pressed event is finished.