问题描述
我们需要每天早上7点运行重复通知,并且内容不是静态的,而是动态的
内容需要从API获取
有没有办法在ios和android中快速实现
在服务器端没有做任何事情吗?
我们使用https://pub.dev/packages/flutter_local_notifications并没有解决问题?
我们正在为现有网站开发应用程序,并且客户拥有所有API,并且他们未使用FCM。他们不会在服务器端进行任何更改,因此强烈建议仅从应用程序端进行处理。
如果我们使用Firebase消息传递库,是否可以在ios和android应用程序中在后台进行通知和API调用?
解决方法
在pubsub中使用firebase函数。在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);
});
在颤抖中使用此软件包 Firebase messaging lib
从此处了解如何使用Firebase消息通知。 Flutter firebase notification tutorial
如果您有任何疑问,请告诉我。