每天安排不同的通知
我是Flutter的新手.我正在开发一个带有通知的应用,该通知将在一天的不同时间显示.
I am a newbie on Flutter. I am developing an app with notifications where notifications will be shown in different parts of the day.
例如:(3:25 AM,12:24 PM,17:22 PM,19:52 PM,21:02 PM).
For instance: (3:25 AM, 12:24 PM, 17:22 PM, 19:52 PM, 21:02 PM).
这些时间将根据一天而有所不同.时间与相应的日期一起存储在数据库中.即使该应用已终止且未使用,也应显示这些通知.
These times will differ based on the day. Times are stored on DB with their corresponding days. These notifications should be displayed even if the app is terminated and not being used.
问题:
- 在新的一天的午夜左右获取新数据.(例如,我的应用程序应在凌晨00:00左右重新安排所有昨天的通知,并以新的时间重新安排,以通知用户正确的数据)
- 我正在使用 flutter_local_notifications 安排通知时间.有时它不会触发通知(如果计划的时差超过2小时).这就是为什么我要安排最快的通知(例如,如果通知应出现在凌晨3:25,那么我想在30分钟前安排通知).但是我不确定是否可行.
- Get new data on around midnight for the new day. (For example around 00:00 AM my app should reschedule all yesterdays' notifications with new times to inform the user with correct data)
- I am using flutter_local_notifications to schedule notification. Sometimes it will not fire a notification (if the scheduled time difference is more than 2 hours). That's is why I am going to schedule the soonest notification (for example if notifications should appear 3:25 AM then I want to schedule notifications 30 minutes before). But I am not sure if it is possible.
我尝试过的事情.
-
background_fetch 用于与数据库同步时间,但我无法使其工作
background_fetch for syncing time with DB but I could not make it work
flutter_local_notifications 用于显示通知
请考虑以下情况:即使我的应用未运行或在后台也要显示通知,并且我希望同时支持Android和iOS
Please consider the case that I want to show the notifications even my app is not running or in the background as well as I want to support both Android and iOS
欢迎任何帮助或建议.预先感谢
Any help or suggestions are welcome. Thanks in advance
对于那些面临相同问题的人,我设法通过以下配置来解决我的问题
For those who are facing the same issue, I managed to solve my problem by the following config
Future<void> initPlatformState() async {
var config = BackgroundFetchConfig(
minimumFetchInterval: 15,
forceAlarmManager: true,
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true,
requiresBatteryNotLow: false,
requiresCharging: false,
requiresStorageNotLow: false,
requiresDeviceIdle: false,
requiredNetworkType: NetworkType.NONE,
);
BackgroundFetch.configure(config, _onBackgroundFetch);
}
Github存储库以查看工作代码.不要忘了支持,如果答案有帮助,请投票并在github上加个星号
Github repo to see the working code. Do not forget to support, if the answer is helpful, upvoting the answer and give a star on github