如何在 Swift 中多次显示通知? [英] How to show Notification in Swift more than once?

查看:48
本文介绍了如何在 Swift 中多次显示通知?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无论如何要每 15 秒显示一次 swift 通知吗?我通过

Is there anyway to show the notification with swift every 15 seconds ? I checked that via

notification.fireDate=NSDate(timeIntervalSinceNow: 15)

但它不是每次只显示一次就起作用,我们如何将其作为循环来执行?

but it doesn't work everytime it just showed once , how we can do it as a loop ?

推荐答案

您不能每 15 秒安排一次通知.通知之间的最短时间为 1 分钟,这也不太可能需要.

You can't schedule a notification every 15 second. The minimum time between notifications it is 1 minute which it is also very unlikely needed.

var repeatInterval: NSCalendarUnit { get set }

var repeatInterval: NSCalendarUnit { get set }

描述重新安排时间的日历间隔通知.如果您分配日历单位,例如每周(NSWeekCalendarUnit) 或每年 (NSYearCalendarUnit),系统在指定的时间间隔重新安排发送通知.请注意,不支持小于一分钟的间隔.这默认值为 0,表示系统触发通知一次,然后丢弃它.

Description The calendar interval at which to reschedule the notification. If you assign a calendar unit such as weekly (NSWeekCalendarUnit) or yearly (NSYearCalendarUnit), the system reschedules the notification for delivery at the specified interval. Note that intervals of less than one minute are not supported. The default value is 0, which means that the system fires the notification once and then discards it.

所以只需如下设置:

notification.repeatInterval = .Minute

这篇关于如何在 Swift 中多次显示通知?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆