我有一种情况,想添加药物的本地提醒。该提醒可以是我每天使用的所有药物的每周或每周一次,用药时间可以是几个月。我已经知道iOS中只有64个通知/应用限制。目前,我使用的代码具有重复的true值,但是可以进行通知,但是我不能将它们限制在特定日期。谁能帮助我,以便我可以设置每日和每周的通知,并且不能超过64个限制?
let calender = Calendar.current
// let gmtZone = TimeZone(secondsFromGMT: 0)
// let dateFormatter = DateFormatter()
// dateFormatter.dateFormat = "yyyy-MM-dd HH:mm";
// dateFormatter.timeZone = gmtZone
// let dateString = dateFormatter.string(from: Date())
let date = Date()//dateFormatter.date(from: dateString)
var componentsFireDate = calender.dateComponents([.year, .day, .month,.hour ,.minute], from: date)
componentsFireDate.day = componentsFireDate.day! + expireIn
componentsFireDate.hour = hour
componentsFireDate.minute = minutes
componentsFireDate.second = 0
let fireDate = calender.date(from: componentsFireDate)
print("Date %@",fireDate!)
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
// content.title = title
content.body = body
content.sound = UNNotificationSound.default()
// content.categoryIdentifier = identifier
// let dailyComp = Calendar.current.dateComponents([.hour, .minute,.second], from: fireDate!)
let timeTrigger = UNTimeIntervalNotificationTrigger(timeInterval:60, repeats: true)
// let trigger = UNCalendarNotificationTrigger(dateMatching: dailyComp, repeats: false)
let request = UNNotificationRequest(identifier:identifier, content: content, trigger: timeTrigger)
center.add(request)