swift3 - How to cancel particular recurring local notification and reschedule it for next week in iOS 10(Swift) -
i have created different local notifications set weekdays , weekends repeat continuously
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 not authorized user") } } unusernotificationcenter.current().add(request) {(error) in if error != nil { print("error: \(error?.localizeddescription)") } }
and cancelling particular notification verifying notifications based on proper conditions , updating same notification next week.
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) }
and updating next fire date using
func getupdatednotification(currentdate: date, firedate : date) ->date { let calendar = calendar.autoupdatingcurrent let datecomponents = (calendar nscalendar).components(([.year, .month, .day]), from: currentdate) let timecomponents = (calendar 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! }
even after removing notification firing removed date because of repeat 'true'.
is there option adding start date in local notifications in ios 10?
thanks in advance!!
you can add logic nexttriggerdate()
func nexttriggerdate()
the next date @ trigger conditions met.
discussion
use property find out when notification associated trigger next delivered.
Comments
Post a Comment