I have created an iOS app that sends a local notification daily at 11:00 AM.
I have followed this!
and my code is...
func setNotification(){
let calendar: NSCalendar = NSCalendar(calendarIdentifier: NSCalendarIdentifierGregorian)!
var dateFire=NSDate()
var fireComponents=calendar.components([.Month, .Day, .Hour, .Minute], fromDate:NSDate())
if (fireComponents.hour >= 11) {
dateFire=dateFire.dateByAddingTimeInterval(86400) // Use tomorrow's date
fireComponents=calendar.components([.Month, .Day, .Hour, .Minute], fromDate:NSDate())
}
fireComponents.hour = 11
fireComponents.minute = 00
dateFire = calendar.dateFromComponents(fireComponents)!
let localNotification = UILocalNotification()
localNotification.fireDate = dateFire
localNotification.alertTitle = "Title"
localNotification.alertBody = "Body"
localNotification.repeatInterval = NSCalendarUnit.Day
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
}
Now the app works good and notifications are sent at 11:00 AM daily but the problem is they are incrementing by one daily :(
Yesterday I had received 6 notifications and today I received 7 at 11:00am
Please help me to get out of this issue.
Thanks!