我目前正在制作一个闹钟应用,目前我可能只是误会.我想在特定时间启动本地通知,然后每隔一段时间重复一次.我已经有了一些想法,这个( 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更多推荐
在特定时间触发后如何重复本地通知
发布评论