如何使用Firebasemessaging的Flutter MethodChannel。
我正在使用 firebase_messaging inbackgroundMessage
预期的。现在,我想从此处理程序中调用平台方法,但我无法做到这一点。 MethodChannel>在此刻。我能够通过在此处创建自定义的幻影插件并实现方法通道来解决我的问题,但这有一些问题:
- 必须管理单独的插件代码 - 不必要的样板和努力
- 在主机应用程序代码和插件代码之间进行通信(例如,想要使用某些方法这是在主机应用程序中的平台侧实现的)。
因此,问题是:如果没有插件,是否可以实现同一件事(例如,创建MethodChannel并在全球范围内注册)。如果插件有可能,则也应该进行主应用程序。目前,如果这使事情变得更容易,我只需要覆盖Android。
I'm using firebase_messaging onBackgroundMessage
handler for listening push messages and it works as expected. Now I want to call platform method from this handler, but I'm unable to do this. MethodChannel can only be registered to Android Activity, but there is no Activity at this point. I was able solve my problem by creating custom Flutter plugin and implementing MethodChannel there, but this has some problems:
- Have to manage separate plugin code - unnecessary boilerplate and effort
- Hard to communicate between host application code and plugin code (e.g. wanting to use some method that is implemented on platform side in host application).
So the question is: is it possible to achieve same thing without plugin (e.g. create MethodChannel and register it globally). If it is possible for plugins, it should be possible for main application as well. Currently I only need to cover Android, if this makes things easier.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论