使用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,如果发现的内容超出预期,这就是问题的根源。

关于ios - UILocalNotification repeatInterval不断推送通知,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30623066/

10-09 17:55
查看更多