[英]Flutter yearly local notifications
我想开发一个生日应用程序,它应该每年向每个人发送一个通知。
我已经在使用“flutter_local_notifications”package,它具有定期显示通知的功能,但不是每年一次。 目前我只是确定每个人的下一个生日,每次用户打开应用程序时,都会安排通知。 但如果有人在一年内没有打开该应用程序,他将不会收到通知。
有人对此有解决方案吗?
如果您想使用“flutter_local_notifications”package 实施年度通知,这里有一个解决方法:
import 'package:timezone/data/latest_all.dart' as tz;
import 'package:timezone/timezone.dart' as tz;
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
List<tz.TZDateTime> scheduledDateTimes = [];
int numberOfYears = 7; // Define how many years you want this notification to show
int notificationID = Random().nextInt(1000000);
DateTime startDate = DateTime.now(); // Define the starting date of this yearly notification
for (int i = 0; i < numberOfYears; i++) {
scheduledDateTimes.add(tz.TZDateTime(tz.local, date.year + i, date.month,
date.day);
}
scheduledDateTimes.asMap().forEach((index, dateTime) async {
await flutterLocalNotificationsPlugin.zonedSchedule(
int.parse("$notificationID$index"),
title,
'Notification title',
dateTime,
notificationDetails,
androidAllowWhileIdle: true,
uiLocalNotificationDateInterpretation:
UILocalNotificationDateInterpretation.absoluteTime);
});
另外,请注意您可以安排的本地通知数量限制为 android 为 50 个,iOS 为 64 个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.