启用 FirebaseMessaging.onBackgroundMessage 时,Webview 中的回调停止工作

问题描述 投票:0回答:0

开发同时使用PUSH通知和WebView的应用程序时,出现调用FirebaseMessaging.onBackgroundMessage后,WebView中的StreamSubscription调用停止的问题。 GitHub 上有个一样意思的registered error,但是上面没有动静。你能告诉我你还能做什么吗?

示例代码:

late StreamSubscription<String> _onUrlChanged;
....
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);
....
}
@override
void initState() {
...
_onUrlChanged = flutterWebViewPlugin.onUrlChanged.listen((String url) {
  print("URL: $url");
});
...
 @override
  Widget build(BuildContext context) {
    return  WebviewScaffold(
      ignoreSSLErrors: true,
      url: selectedUrl,
      javascriptChannels: jsChannels,
      mediaPlaybackRequiresUserGesture: false,
      appBar: AppBar(
        title: const Text('Widget WebView'),
      ),
      withZoom: true,
      withLocalStorage: true,
      hidden: false,
      initialChild: Container(
        color: Colors.redAccent,
        child: const Center(
          child: Text('loading...'),
        ),
      ),
    );
  }

只要我删除行 FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler); 一切立即开始工作

flutter firebase webview push
© www.soinside.com 2019 - 2024. All rights reserved.