android - 我们需要每天早上 7 点运行重复通知,并且内容是动态的
问题描述
我们需要每天早上 7 点运行重复通知,并且内容不是静态的,而是
需要从 API 获取的动态内容
是否有任何方法可以在 ios 和 android 的颤振中做到这一点而无需
从服务器端做任何事情?
我们使用了https://pub.dev/packages/flutter_local_notifications并没有解决问题?
我们正在为现有网站开发应用程序,客户拥有所有 API,但他们没有使用 FCM。他们不会在服务器端进行任何更改,并且强烈建议仅从应用程序端进行处理。
如果我们使用 Firebase 消息传递库,是否可以在 ios 和 android 应用程序中在后台进行通知和 API 调用?
解决方案
将 firebase 函数与 pubsub 一起使用。在 firebase 函数中使用此代码。
const admin = require('firebase-admin');
const fcm = admin.messaging();
exports.dailyNotification = functions.pubsub.schedule('0 7 * * *')
.onRun((context) => {
//tokens need to be unique to send notifications per device
//you can call data from firebase firestore to change the notification contents
const payload = admin.messaging.MessagingPayload = {
notification: {
title: 'Notification title',
body: 'This is a notification message',
icon: 'your-icon-url',
click_action: 'FLUTTER_NOTIFICATION_CLICK'
}
};
/*this token you need to save from flutter. You need it only when you
need to send specific notification to the specific device*/
fcm.sendToDevice(tokens.token, payload);
});
在Flutter Firebase 消息传递库中使用这个包
从这里了解如何使用 firebase 消息通知。 Flutter firebase 通知教程
如果您有任何问题,请告诉我。
推荐阅读
- amazon-web-services - 在 docker 容器中运行 CDK 时无法解析要使用的 AWS 账户
- python - 无法在 Macbook 上安装 pylint
- html - 在 iOS 应用程序的背景中查找 html 中的值
- django - 如何在 django 项目中导入和显示 csv 文件
- wordpress - 如何在 ClickFunnels 页面上的灯箱中自动播放视频?
- git - 日期错误的 Git 提交
- javascript - 如何通过在javascript中单击鼠标触发输入中的按键
- javascript - 我如何知道某个元素是否在屏幕上?
- vee-validate - 使用带有 vee-validate 的日期类型
- zsh - 如何在我的 zsh 主题中有条件地打印返回码?