Scheduling UILocalNotifications

Hi,



I have written some code to allow for UILocalNotifications but using the code below, it doesn't show on the triggered time and date I think due to the fact that the NSCalendar is not set to Georgian?! I currently have it set to: NSCalendar.currentCalendar()



Please help?




//date
        var dateComp:NSDateComponents = NSDateComponents()
        dateComp.year = 2016
        dateComp.month = 02
        dateComp.day = 04
        dateComp.hour = 21
        dateComp.minute = 49
        dateComp.timeZone = NSTimeZone.systemTimeZone()
       
        var calendar:NSCalendar = NSCalendar.currentCalendar()
        var date:NSDate = calendar.dateFromComponents(dateComp)!
       
        var notification:UILocalNotification = UILocalNotification()
        notification.category = "FIRST_CATEGORY"
        notification.alertAction = "heyaaa, I notified you"
        notification.fireDate = date
       

        Application.sharedApplication().scheduleLocalNotification(notification)

If you’re trying to convert a set of date components to a date,

dateFromComponents(_:)
is the right method to use. Date components are always relative to a specific calendar—for example, this year is the year 2559 in the Buddhist calendar—so if you’re hardwiring components that assume the Gregorian calendar you will need to use that calendar when calling
dateFromComponents(_:)
. Finally, you don’t need to set the time zone in your date components; the calendar always assumes the current time zone unless you override that via its
timeZone
property.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"
Scheduling UILocalNotifications
 
 
Q