【问题标题】:How to receive Huawei push in flutter when app is killed?应用被杀时如何接收华为推送?
【发布时间】:2021-05-21 00:30:19
【问题描述】:

尝试在 Flutter 应用中设置华为推送,但在应用不运行时遇到了一些问题。

应用在前台和后台运行时收到推送。但是当它被杀死时,它不会收到推送,或者有时不是实时的,或者直到应用重新打开。

这里可能缺少什么?

【问题讨论】:

    标签: huawei-mobile-services huawei-developers huawei-push-notification


    【解决方案1】:

    当应用在后台运行或应用进程被杀死时,接收数据消息时不会调用onMessageReceivedStream处理程序。

    相反,您需要通过 registerBackgroundMessageHandler 方法设置后台回调处理程序。

    要设置后台处理程序,请尽早在应用逻辑之外调用 registerBackgroundMessageHandler。

    例如示例代码:

    package com.huawei.hms.flutter.push_example;
    
    import com.huawei.hms.flutter.push.PushPlugin;
    
    import io.flutter.app.FlutterApplication;
    import io.flutter.plugin.common.PluginRegistry;
    import io.flutter.plugins.GeneratedPluginRegistrant;
    
    
    
    public class Application extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {
        @Override
        public void onCreate() {
            super.onCreate();
            PushPlugin.setPluginRegistrant(this);
        }
    
        @Override
        public void registerWith(PluginRegistry registry) {
            GeneratedPluginRegistrant.registerWith(registry);
        }
    }
    

    另外,请仔细检查link 中的基本集成步骤:

    【讨论】:

      猜你喜欢
      • 2017-04-12
      • 1970-01-01
      • 2018-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多