我已經創建了不同的本地通知,爲工作日和週末設置爲重複不斷如何取消特定重複本地通知,並重新計劃下週在iOS的10(SWIFT)
let trigger = UNCalendarNotificationTrigger(dateMatching: triggerWeekly, repeats: true)
let content = UNMutableNotificationContent()
content.body = "TIME_TO_STEP_SHAPA".localized
content.sound = UNNotificationSound.default()
let request = UNNotificationRequest(identifier: "\(notificationType)-\(reminderType)-\(day)", content: content, trigger: trigger)
UNUserNotificationCenter.current().getNotificationSettings { (settings) in
if settings.authorizationStatus != .authorized {
print("Local notifications are not authorized by the user")
}
}
UNUserNotificationCenter.current().add(request) {(error) in
if error != nil {
print("Error: \(error?.localizedDescription)")
}
}
和取消特別通知,確認基於適當條件的通知並在下週更新相同的通知。
if (type == notificationType && notificationWeekDay == currentWeekDay) {
//Cancelling local notification
app.cancelLocalNotification(notif)
let fireDate = self.getUpdatedNotification(currentDate: currentLocalDate!, fireDate: notificationFireDate!)
HikeCommonUtils.setUpLocalNotification(fireDate, type: notificationType, reminderType: reminderType)
}
和即使在拆除通知解僱,因爲重複的「真」的刪除日期後更新使用
func getUpdatedNotification(currentDate: Date, fireDate : Date) ->Date {
let calendar = Calendar.autoupdatingCurrent
let dateComponents = (calendar as NSCalendar).components(([.year, .month, .day]), from: currentDate)
let timeComponents = (calendar as NSCalendar).components(([.hour, .minute, .second]), from: fireDate)
var dateComps = DateComponents()
dateComps.day = dateComponents.day! + 7
dateComps.month = dateComponents.month
dateComps.year = dateComponents.year
dateComps.hour = timeComponents.hour
dateComps.minute = timeComponents.minute
dateComps.second = timeComponents.second
let itemDate = calendar.date(from: dateComps)
return itemDate!
}
下一個火日期。
是否有任何選擇在iOS 10的本地通知中添加開始日期?
在此先感謝!