The date specified in fireDate is interpreted according to the value
of this property. If you specify nil (the default), the fire date is
interpreted as an absolute GMT time, which is suitable for cases such
as countdown timers. If you assign a valid NSTimeZone object to this
property, the fire date is interpreted as a wall-clock time that is
automatically adjusted when there are changes in time zones; an
example suitable for this case is an an alarm clock.
localNotification.fireDate = timePicker.date
localNotification.timeZone = NSTimeZone.defaultTimeZone()
// the problem is here, you are setting the timezone after inputing your date
you should use localtimeZone and set it before setting the fireDate
localNotification.timeZone = NSTimeZone.localTimeZone()
localNotification.fireDate = timePicker.date
Note:
In iOS 8 and later, apps that use either local or remote notifications
must register the types of notifications they intend to deliver. The
system then gives the user the ability to limit the types of
notifications your app displays. The system does not badge icons,
display alert messages, or play alert sounds if any of these
notification types are not enabled for your app, even if they are
specified in the notification payload.
do like this:
UIApplication.sharedApplication().registerUserNotificationSettings(UIUserNotificationSettings(forTypes: UIUserNotificationType.Badge | UIUserNotificationType.Sound | UIUserNotificationType.Alert, categories: nil))
create an extension to combine the time picked with 0 seconds as follow:
extension NSDate {
var day: Int { return NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitDay, fromDate: self).day }
var month: Int { return NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitMonth, fromDate: self).month }
var year: Int { return NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitYear, fromDate: self).year }
var minute: Int { return NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitMinute, fromDate: self).minute }
var hour: Int { return NSCalendar.currentCalendar().components(NSCalendarUnit.CalendarUnitHour, fromDate: self).hour }
var fireDate: NSDate {
return NSCalendar.currentCalendar().dateWithEra(1, year: year, month: month, day: day, hour: hour, minute: minute, second: 0, nanosecond: 0)!
}
}
then just use it as follow:
localNotification.fireDate = timePicker.date.fireDate