微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

已安排本地通知停机工作NotificationRepeatFrequency

如何解决已安排本地通知停机工作NotificationRepeatFrequency

当我尝试实现函数chedulednotificationRepeatFrequency并每天设置时,通知后的第二天没有出现?如何在确定的小时和分钟上设置每日通知? 这是我的代码

Future<void> _scheduleDailyNotification(
  int id,String title,int nday,int hour,int minute,) async {
  int nhour = hour - TimeOfDay.Now().hour;
  int nminute = minute - TimeOfDay.Now().minute;
  print(hour);
  print(nhour);
  print(nminute);
  var androidplatformchannelspecs = AndroidNotificationDetails(
  '1','xClock title','xClock description',channelAction: AndroidNotificationChannelAction.createIfNotExists,icon: 'ic_xclockicon',sound: RawResourceAndroidNotificationSound('ringstone'),largeIcon: DrawableResourceAndroidBitmap('ic_xclockicon'),);
  var iosplatformchannelspecs = IOSNotificationDetails(
    presentAlert: true,presentBadge: true,presentSound: true,sound: 'ringstone.wav');
  await FlutterlocalnotificationsPlugin.zonedSchedule(
  id,title,'xClock è tempo di $title',_nextInstanceOfTenAM(nday,nhour,nminute),NotificationDetails(
      android: androidplatformchannelspecs,iOS: iosplatformchannelspecs,macOS: null),androidAllowWhileIdle: true,uilocalnotificationDateInterpretation:
      UIlocalnotificationDateInterpretation.absoluteTime,schedulednotificationRepeatFrequency:
      SchedulednotificationRepeatFrequency.daily);
 }


tz.TZDateTime _nextInstanceOfTenAM(int nday,int nhour,int nminute) {
final tz.TZDateTime Now = tz.TZDateTime.Now(tz.local);
tz.TZDateTime scheduledDate = tz.TZDateTime.Now(tz.local)
  .add(Duration(days: nday,hours: nhour,minutes: nminute))
  .subtract(Duration(seconds: Now.second));

if (scheduledDate.isBefore(Now) || nday < 0) {
(scheduledDate.isBefore(Now))
    ? scheduledDate = scheduledDate.add(const Duration(days: 7))
    : scheduledDate = scheduledDate.add(const Duration(days: 0));
 } else {}
 print('schedule');
 print(scheduledDate);
 return scheduledDate;
 }

我尝试了FlutterlocalnotificationsPlugin.periodicallyShow,但我只能选择每天,每小时,每周,每分钟,但我也想选择弹出窗口的时间

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。