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