如何在ios 10 Swift3中安排多个本地通知

时间:2017-06-12 13:29:47

标签: ios swift3

其实我做了本地通知调度,但它只安排了一个通知。我有提醒模型数组,每个模型对象包含标题,注释,任务ID,日期这样的不同信息。所以使用for循环我正在设置通知内容,触发器,标识符和发出请求但不显示通知。以下是我的代码
.................................................. ...........................

func setNotification(tasks:[RemiderModel]){    

    for i in stride(from: 0, to: tasks.count, by: 1)
    {

        self.scheduleLocal(task: tasks[i])

    }
}

func scheduleLocal(task:RemiderModel)
{

    //let center = UNUserNotificationCenter.current()
    //center.delegate = self

    let content = UNMutableNotificationContent()
    content.title = task.mTitle
    //content.subtitle = "Rahul"//array[i]["title"]!
    content.body = task.mNotes//array[i]["note"]!
    content.sound = UNNotificationSound.default()
    content.badge = 1
    let triggerTime = Calendar.current.dateComponents([.hour,.minute], from: task.reminder)

    let trigger = UNCalendarNotificationTrigger(dateMatching: triggerTime, repeats: false)

    let request = UNNotificationRequest(identifier: task.taskID, content: content, trigger: trigger)

    UNUserNotificationCenter.current().add(request, withCompletionHandler: {error in
        if error != nil
        {
            print(error!)
        }

    })

  override func viewDidLoad()
{
    super.viewDidLoad()
    UNUserNotificationCenter.current().delegate = self
}

0 个答案:

没有答案