iOS Swift Local notification not "popping up"
Your issue is the way you are converting the NSDateComponents object to an NSDate.
Simply calling components.date
without setting a calendar
for the NSDateComponents
object will return nil
.
Try using this instead:
notification.fireDate = calendar.dateFromComponents(components)
Alternatively, you can set the calendar
property on the components object:
components.calendar = calendar
Because you are setting the fireDate
property on the notification object to nil
, it will fire immediately, i.e. before you have a chance to close the app and lock the screen. This behavour is documented in the UILocalNotification class reference