我正在为我的应用程序开发一个提醒功能 . 它适用于iOS 9和iOS 10.我使用iOS 9的UILocalNotification和ios 10的UNUserNotificationCenter . 这是我的应用程序的图片:
User can choose the weekday that they want to repeat
And they can choose the minute repeat for each time
每次重复的想法是创建一个新的通知,但为它添加分钟 . 例如,如果你想重复5分钟我得到第一次通知时间并加上5分钟然后重复2次 . 它在iOS 10上使用UNUserNotificationCenter非常完美,但在iOS 9中我遇到了一些麻烦 . 每次推送一个数字通知,与您选择的当天数相同 . 例如,如果你选择三天是星期四,星期五,萨尔它会推3 Notification for each time .
如果你选择三天是周四,周五,萨尔 . arrDay是[5,6,7]所以这循环3次
for day in arrDay {
setNotification(weekDay: day, title: titleAlert, sound: sound, setTime: getTime(), identifi: identifi)
}
这是函数setNotification:
{
let notification = UILocalNotification()
notification.alertTitle = title
notification.alertBody = "Đã đến giờ hẹn. Hãy dành một ít thời gian để cũng cố kiến thức nào!"
notification.soundName = sound
if sound == "Mặc định" {
notification.soundName = UILocalNotificationDefaultSoundName
}
notification.userInfo = [identifi: identifi]
let time = Calendar.current.dateComponents([.month,.day,.weekday,.hour,.minute,.second], from: setTime)
var dates = DateComponents()
dates.weekday = weekDay
dates.hour = time.hour
dates.minute = time.minute
let fireTime = Calendar.current.date(from: dates)
notification.fireDate = fireTime
notification.repeatInterval = .weekday
UIApplication.shared.scheduleLocalNotification(notification)
}