我知道已经发布了一些相似的主题,但是我已经跟着他们并且仍然遇到了同样的问题。
我的AppDelegate:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
let notificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
UIApplication.sharedApplication().registerUserNotificationSettings(notificationSettings)
application.beginBackgroundTaskWithName("showNotification", expirationHandler: nil)
return true
}
func application(application: UIApplication, didReceiveLocalNotification notification: UILocalNotification) {
let alertView = UIAlertController(title: "Alert", message: "Notification Got", preferredStyle: .Alert)
self.window?.rootViewController?.presentViewController(alertView, animated: true, completion: nil)
}
构建和安排通知的My Notifier对象
func scheduleNotifications(reminder: ReminderMO) {
let notification = UILocalNotification()
notification.alertTitle = reminder.name
notification.alertBody = reminder.name
notification.alertAction = "open"
notification.soundName = UILocalNotificationDefaultSoundName
notification.repeatInterval = .Day
notification.timeZone = NSTimeZone.defaultTimeZone()
notification.fireDate = reminder.timeRange?.startDate
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
reminder.timeRange?.startDate
是一个NSDate
对象,当我检查它时,它似乎是我所期望的。它来自UIDatePicker
。
问题是,当我在didReceiveLocalNotification
函数上断点时,它永远不会触发。