Skip to content

Instantly share code, notes, and snippets.

@ChrisLTD
Created May 29, 2015 15:24
Show Gist options
  • Save ChrisLTD/acea88ca751c05af929b to your computer and use it in GitHub Desktop.
Save ChrisLTD/acea88ca751c05af929b to your computer and use it in GitHub Desktop.
class func setupNotificationFor(hourTask:HourTask) {
// clear all old notification first if there is one
for notification in UIApplication.sharedApplication().scheduledLocalNotifications as! [UILocalNotification] {
if (notification.userInfo!["UUID"] as! String == hourTask.theID) {
UIApplication.sharedApplication().cancelLocalNotification(notification)
println("old notification removed")
break
}
}
if !hourTask.task.isEmpty {
let now = NSDate()
let date = DayDataManager.createDateWith(hourTask.date, andMinutes: hourTask.time.integerValue)
if now.compare(date) == NSComparisonResult.OrderedAscending {
let notification = UILocalNotification()
notification.fireDate = date
notification.alertBody = hourTask.task
notification.alertAction = "OK"
notification.soundName = UILocalNotificationDefaultSoundName
notification.userInfo = ["UUID": hourTask.theID]
UIApplication.sharedApplication().scheduleLocalNotification(notification)
println("notification scheduled")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment