UILocalNotification 重复间隔不起作用

UILocalNotification repeat interval not working

我试图让 UILocalNotification 每秒重复一次,它确实在重复,但由于某种原因不是每秒重复一次,它似乎每分钟都重复一次,我对 UILocalNotifications 还是个新手,所以我可能做错事。这是通知的图片: http://imgur.com/Hzt38py

这是我用来创建 UILocalNotification 的函数

       func notificationCreater (date:NSDate, uuid:String) {

    let notification = UILocalNotification ()

    notification.alertBody = "Test Run 9"

    notification.fireDate = date
    notification.repeatInterval = NSCalendarUnit.CalendarUnitSecond
    //notification.userInfo = ["UUID": uuid]
    //  notification.soundName = "alarmSound.m4a"
    //        notification.alertAction = "he"
    // notification.soundName = "alarmSound.m4a"
    // notification.alertTitle = "Test Title"

    println("schld")
    UIApplication.sharedApplication().scheduleLocalNotification(notification)
}

这是视图控制器的其余部分

class AddTaskViewController: UIViewController,AVAudioPlayerDelegate{

    @IBOutlet weak var taskTextField: UITextField!


    @IBOutlet weak var dueDatePicker: UIDatePicker!
    var delegate = AddTaskViewControllerDelegate?()



    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.backgroundColor = UIColor(patternImage: UIImage(named: "Background")!)


        // Do any additional setup after loading the view.
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

    @IBAction func cancelButtonTapped(sender: UIButton) {
        self.dismissViewControllerAnimated(true, completion: nil)

        delegate?.addTaskCanceled!("task canceled")
        UIApplication.sharedApplication().cancelAllLocalNotifications()

    }

    @IBAction func addTaskButtonTapped(sender: UIButton) {

        let appDelegate = (UIApplication.sharedApplication().delegate as! AppDelegate)

        let managedObjectContext = appDelegate.managedObjectContext
        let entityDescription = NSEntityDescription.entityForName("TaskModel", inManagedObjectContext: managedObjectContext!)
        let task = TaskModel(entity: entityDescription!, insertIntoManagedObjectContext: managedObjectContext!)

        task.task = taskTextField.text

        task.date = dueDatePicker.date
        task.uuid = NSUUID().UUIDString
        //if NSUserDefaults.standardUserDefaults().boolForKey(kShouldCompleteNewTodoKey) == true {task.completed = true}
        task.completed = false

        appDelegate.saveContext()


        let calendar = NSCalendar.currentCalendar()
        let comp = calendar.components(NSCalendarUnit.CalendarUnitSecond, fromDate: task.date)


        let seconds = Double(comp.second)
        //        let notification = UILocalNotification()
        //        notification.alertBody = "testBody"
        //        notification.fireDate = dueDatePicker.date
        //        notification.alertTitle = "testTitle"
        println("seconds:\(seconds)")

        var request = NSFetchRequest(entityName: "TaskModel")
        var error:NSError? = nil

        var results:NSArray = managedObjectContext!.executeFetchRequest(request, error: &error)!
        notificationCreater(dueDatePicker.date, uuid: task.uuid)

        self.dismissViewControllerAnimated(true, completion: nil)
    }

单击添加任务按钮时会创建通知,但不会每秒重复一次。我究竟做错了什么?

**还有人知道如何在 phone 处于 "Do Not Disturb" 或静音模式时播放通知声音

应用程序应该在后台触发通知。如果您想在应用程序处于前台时也触发通知,请实施

func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification){

}

来自 Apple 的文档repeatInterval

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.