[英]UILocalNotification repeatInterval keeps pushing notifications
使用repeatInteval时,无论设置为“分钟/天/小时”等,通知都将一个接一个地推送。
直到我每隔几秒钟进行一次测试,设置似乎都不会变回原来的样子,它的确运行良好。 有什么原因吗?
var dateComp:NSDateComponents = NSDateComponents()
dateComp.year = 2015;
dateComp.month = 06;
dateComp.day = 03;
dateComp.hour = 15;
dateComp.minute = 27;
dateComp.timeZone = NSTimeZone.systemTimeZone()
var calender:NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
var date:NSDate = calender.dateFromComponents(dateComp)!
var notification:UILocalNotification = UILocalNotification()
notification.category = "Daily"
notification.alertBody = "OK"
notification.fireDate = date
notification.repeatInterval = NSCalendarUnit.CalendarUnitDay
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(notification)
如果您将通知设置为使用CalendarUnitDay重复,则它应在第一次触发后的同一时间每天重复一次。 请注意,删除计划的通知不足以删除应用程序(至少在iOS7中是如此),因为系统会将通知保持注册状态,但保持沉默24小时,以避免意外卸载。
也许您仍然看到预定的旧通知。
要确保设置一个断点,并向应用程序委托提供其-scheduledNotifications
如果发现的内容超出预期,这就是问题的根源。
如果您每隔几秒钟进行一次测试,则意味着所有通知都已安排好并将被接收。 尝试先取消所有计划的通知,然后在所需的时间间隔重新计划
UIApplication.sharedApplication().cancelAllLocalNotifications()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.