昨天設定完推播的內容後,今天就來產生推播吧。
這裡是在顯示Cell的同時,一起產生推播。
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! AlarmTableViewCell
let realm = try! Realm()
let cells = realm.objects(AlarmRealm.self)
let repeatDays = [cells[indexPath.row].Sunday,
cells[indexPath.row].Monday,
cells[indexPath.row].Tuesday,
cells[indexPath.row].Wednesday,
cells[indexPath.row].Thursday,
cells[indexPath.row].Friday,
cells[indexPath.row].Saturday]
var repeatDayCount = 0
cell.tag = indexPath.row
cell.timeLabel.text = String(format: "%2d:%02d", arguments: [cells[indexPath.row].Hour, cells[indexPath.row].Minute])
cell.timeLabel.font = cell.timeLabel.font.withSize(60)
cell.soundLabel.text = addPageValue.pageValue.soundSource[cells[indexPath.row].soundSelect]
if cells[indexPath.row].switchOnOff {
cell.onOffSwitch.isOn = true
createNotificationId(selectRow: indexPath.row)
for i in 1...7 {
if repeatDays[i-1] {
createNotification1(selectRow: indexPath.row, repeatDay: i)
repeatDayCount += 1
}
}
if repeatDayCount == 0 {
createNotification2(selectRow: indexPath.row)
}
} else {
cell.onOffSwitch.isOn = false
}
return cell
}
既然有產生,明天來想辦法刪除推播。