在特定时间触发后如何重复本地通知

编程入门 行业动态 更新时间:2024-10-27 13:33:45
本文介绍了在特定时间触发后如何重复本地通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在制作一个闹钟应用,目前我可能只是误会.我想在特定时间启动本地通知,然后每隔一段时间重复一次.我已经有了一些想法,这个( makeapppie/2017/01/31/how-to-repeat-local-notifications/)程序与我想要的程序接近,但我希望它在某个时间关闭然后重复间隔一个时间.

I am currently making an alarm clock app and I am currently stuck at possibly just a misunderstanding. I want to launch a local notification at a specific time and repeat at a time interval. I have been getting a couple ideas and this (makeapppie/2017/01/31/how-to-repeat-local-notifications/) program is close to what I want it to be but I want it to go off at a certain time and then repeat at a single interval.

用户输入信息后,程序将吐出:

After user inputs information, the program will spit out:

timeIntervalSeconds,用户希望通知的时间间隔(以秒为单位)

timeIntervalSeconds, the interval that user wants the notifications in (in seconds)

timeStart,通知将在何时开始

timeStart, when the notifications will start

timeEnd,如果用户不停止通知,通知将在何时结束

timeEnd, when the notifications will end if the user doesn't stop them

任何建议将不胜感激.

谢谢!

推荐答案

要在特定时间启动通知,请使用以下代码.

To launch notification on specific time use below code.

let gregorian = Calendar(identifier: .gregorian) let now = Date() var components = gregorian.dateComponents([.year, .month, .day, .hour, .minute, .second], from: now) // Change the time to 10:00:00 in your locale components.hour = 10 components.minute = 0 components.second = 0 let date = gregorian.date(from: components)! let triggerDaily = Calendar.current.dateComponents([.hour,.minute,.second,], from: date) let trigger = UNCalendarNotificationTrigger(dateMatching: triggerDaily, repeats: true) let request = UNNotificationRequest(identifier: CommonViewController.Identifier, content: content, trigger: trigger)

要在特定时间间隔重复发送通知,请在触发器中使用以下代码.

And to repeat notifications on specific time interval use below code in trigger.

let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 120, repeats: true) // it repeats after every 2 minutes

更多推荐

在特定时间触发后如何重复本地通知

本文发布于:2023-11-27 02:49:49,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636256.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:通知   时间   在特定

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!