0
我試圖找出如何更新每天重複的本地通知中的消息。如何更新iOS 10中的每日本地通知消息?
目前,我有我的AppDelegate下面的代碼:
func scheduler(at date: Date, numOfNotes: Int)
{
let calendar = Calendar(identifier: .gregorian)
let components = calendar.dateComponents(in: .current, from: date)
let newComponents = DateComponents(calendar: calendar, timeZone: .current, hour: components.hour, minute: components.minute)
let trigger = UNCalendarNotificationTrigger(dateMatching: newComponents, repeats: true)
content.badge = numOfNotes as NSNumber
content.body = "REMINDER: " + String(numOfNotes) + " needs to be looked at!"
content.sound = UNNotificationSound.default()
let request = UNNotificationRequest(identifier: "reminderNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().add(request) {(error) in
}
}
我在UserDefaults
存儲numOfNotes
。我在我的UITableViewCell
一個UISwitch
,即在對呼叫進行切換scheduler
功能,像這樣:
func remindMeSwitch(_ remindMeSwitch: UISwitch)
{
numOfNotes = UserDefaults.standard.integer(forKey: "Notes")
let delegate = UIApplication.shared.delegate as? AppDelegate
delegate?.scheduler(at: time, numOfNotes: numOfNotes)
}
然而,設置repeats
參數true
時每天有通知重複在指定的時間,numOfNotes
只調用一次,這是當我切換UISwitch
。
如何將通知設置爲每日警報但仍能夠根據需要更新通知消息?
謝謝。
那就好像你需要安排適當的個人信息不重複的通知實現這一目標。 – Losiowaty
@Losiowaty,我懷疑是這種情況,但我希望不必每次計數改變時重新計劃 – Pangu
您可以嘗試添加通知服務應用程序擴展,但我不確定是否需要它本地通知。也只有從iOS 10纔可用。 – Losiowaty