我在 Flutter 应用程序中使用 Quickblox 进行聊天。一旦建立连接,聊天就可以正常进行。当应用程序发送到后台时,我按照 Quickblox 文档的建议将连接设置为关闭。但是当我重新打开我的应用程序时,它在其事件中不再收到消息(QBChatEvents.RECEIVED_NEW_MESSAGE)。尽管消息已在日志中发送和接收,但此事件不再起作用。日志显示了这个异常,
Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel:
Run Code Online (Sandbox Code Playgroud)
这是我订阅的活动,
QB.chat.subscribeChatEvent(QBChatEvents.RECEIVED_NEW_MESSAGE,
(data) {
// my implementaion here
});
Run Code Online (Sandbox Code Playgroud)
我从他们的文档中添加了这个实现。
class _SomeScreenState extends State<SomeScreen> with WidgetsBindingObserver {
@override
initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
try {
await QB.chat.connect(userId, userPassword);
} on PlatformException catch (e) {
// …Run Code Online (Sandbox Code Playgroud)