[英]schedule local notification daily in the background
I can use local notifications like this我可以像这样使用本地通知
awesome_notifications: ^0.6.21
Notification class通知 class
class NotificationService {
sendNotification(){
AwesomeNotifications().isNotificationAllowed().then((isAllowed){
if(!isAllowed){
AwesomeNotifications().requestPermissionToSendNotifications();
}
});
AwesomeNotifications().createNotification(content: NotificationContent(id: 2, channelKey: 'key',
title: 'Title',
body: 'Body',
),
);
AwesomeNotifications().actionStream.listen((event) {
Get.toNamed(Routes.HOME_PAGE);
});
}
}
Main call主叫
void main() {
AwesomeNotifications().initialize(null, [NotificationChannel(channelKey: 'key', channelName: 'channelName', channelDescription: 'channelDescription')]);
runApp(const MyApp());
}
My question is how to schedule the notification for example at 4:00 pm daily in the background?我的问题是如何在后台安排例如每天下午 4:00 的通知?
If you want repeats it.. Repeats is determines if the schedule should be repeat after be displayed... Change your "AwesomeNotifications().createNotification" function.如果你想重复它..重复是确定是否应该在显示后重复计划......更改您的“AwesomeNotifications().createNotification”function。
String localTimeZone = await AwesomeNotifications().getLocalTimeZoneIdentifier();
AwesomeNotifications().createNotification(
content: NotificationContent(
id: id,
channelKey: 'scheduled',
title: 'Notification at every 24 hours or 1440 minutes',
body:
'This notification was schedule to repeat at every 24 hours or 1440 minutes.',
notificationLayout: NotificationLayout.BigPicture,
bigPicture: 'asset://assets/images/melted-clock.png'),
schedule: NotificationInterval(interval: 1440, timeZone: localTimeZone, repeats: true));
Look at: https://pub.dev/packages/awesome_notifications看: https://pub.dev/packages/awesome_notifications
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.