简体   繁体   中英

How to show Notification in Swift more than once?

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 ?

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 }

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.

So just set it up as follow:

notification.repeatInterval = .Minute

您可以设置localNotification.repeatInterval财产为类型,其NSCalendarUnit

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM