I am using localNotifications for my app.I have a datepicker from which a users picks date and time for the notifications and I also have 3 segmented controls(daily,weekly,monthly).I have done the coding for localnotification and its working.But the segmented control is not working and one more problem if a person chooses two times like one for(1 pm) and second for (2pm) and then the notifications are displaying in both time which i dont want.Below is the code
In appdelegate.swift
let types:UIUserNotificationType = UIUserNotificationType.Alert | UIUserNotificationType.Badge | UIUserNotificationType.Sound
let myAlarmSetting:UIUserNotificationSettings = UIUserNotificationSettings(forTypes: types, categories: categories as Set<NSObject>)
UIApplication.sharedApplication().registerUserNotificationSettings(myAlarmSetting)
In notifications.swift @IBAction func NotificationButtonTapped(sender: AnyObject) {
var notifications:UILocalNotification = UILocalNotification()
notifications.fireDate = datePicker.date
notifications.timeZone = NSTimeZone.defaultTimeZone()
notifications.applicationIconBadgeNumber = UIApplication.sharedApplication().applicationIconBadgeNumber + 1
notifications.soundName = UILocalNotificationDefaultSoundName
switch(frequencysegmentedcontrol.selectedSegmentIndex){
case 0:
notifications.repeatInterval = NSCalendarUnit.CalendarUnitDay
break;
case 1:
notifications.repeatInterval = NSCalendarUnit.CalendarUnitWeekOfYear
break;
case 2:
notifications.repeatInterval = NSCalendarUnit.CalendarUnitYear
break;
default:
notifications.repeatInterval = NSCalendarUnit(0)
break;
}
notifications.alertBody = "quote of the day"
notifications.category = "First_category"
UIApplication.sharedApplication().scheduleLocalNotification(notifications)
}
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
application.applicationIconBadgeNumber = 0
}