【问题标题】:Firebase custom notifications with FlutterFire使用 FlutterFire 的 Firebase 自定义通知
【发布时间】:2021-09-02 05:24:12
【问题描述】:

借助 Firebase 和 FlutterFire,可以轻松地从服务器定期向用户的设备发送通知。这些通知包括标题、正文和图像 URL。但是如何创建一个不那么简单的通知,比如 Telegram 或 WhatsApp 的呢?

简单的问题是避免从服务器发送Notification,而是将data 字段设置为推送消息。但是根据the FlutterFire documentation

当您的应用程序处于后台或终止时,设备将仅数据消息视为低优先级,并将被忽略

所以,听起来如果我们想要一个可靠的传递系统,我们应该在我们的推送消息中添加一个Notification。但那个通知是如此简单。同样,根据the documentation

如果您的消息是通知消息(包括通知属性),Firebase SDK 将拦截此消息并向您的用户显示可见通知(假设您已请求权限并且用户已启用通知)

所以:如果我想要一个可靠的系统,我必须发送Notifications,但我这样做了,我无法告诉 FlutterFire 使用我的自定义通知。

所以问题是:如何使用 FlutterFire 显示自定义通知?

我想要实现的是这样的:

【问题讨论】:

    标签: firebase flutter push-notification notifications firebase-cloud-messaging


    【解决方案1】:

    我将尝试设置推送通知的优先级。

    You can however explicitly increase the priority by sending additional properties on the FCM payload:
    
    On Android, set the priority field to high.
    On Apple (iOS & macOS), set the content-available field to true.
    

    在服务器端代码,它看起来像:

    message.setAndroidConfig(AndroidConfig.builder().setPriority(AndroidConfig.Priority.HIGH).build());
    message.setApnsConfig(ApnsConfig.builder().setAps(Aps.builder().setContentAvailable(true).build()).build());
    

    【讨论】:

    • 它似乎有效,至少在 Android 上是这样。希望我在测试iOS版本时在这里说点什么。
    猜你喜欢
    • 1970-01-01
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多