Created
May 29, 2015 15:24
-
-
Save ChrisLTD/acea88ca751c05af929b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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