Reputation:
I have found many answers in objective C, but I am looking for a way to create a local notification for every Monday and Tuesday, or every Saturday and Thursday etc etc. In my code I have created a few NSDateComponents
let date2 = NSDateComponents()
date2.hour = 4
date2.minute = 3
let date3 = NSDateComponents()
date3.hour = 12
date3.minute = 33
...
and then put them into an array
datesArray = [date2, date3]
I have found very little resources on how to create local notifications in swift 2 and all i have been able to do so far is create a local notification 10 seconds from when I build and run the application, but this has no connection to the dates i created.
var localNotification = UILocalNotification()
localNotification.fireDate = NSDate(timeIntervalSinceNow: 10)
localNotification.repeatInterval = NSCalendarUnit.Day
localNotification.alertBody = "Take Out Track"
localNotification.timeZone = NSTimeZone.defaultTimeZone()
localNotification.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
UIApplication.sharedApplication().scheduleLocalNotification(localNotification)
What I am trying to do is create a notification for each date in the array, and then have the ability to say only repeat that on Monday Wednesday and Saturday or whatever the user selects.
Upvotes: 0
Views: 537
Reputation: 553
For that you have to use nscalender through which you can get the weekday like in iOS weekday for sunday is 1 , Monday is 2 and so on.... through that you can set on which day you have to fire your notification. and also check out that tuturiol
http://www.appcoda.com/ios-event-kit-programming-tutorial/
Upvotes: 0