iOS 9本地通知无法在模拟器上运行

时间:2016-06-29 03:28:53

标签: ios swift uilocalnotification

我知道已经发布了一些相似的主题,但是我已经跟着他们并且仍然遇到了同样的问题。

我的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函数上断点时,它永远不会触发。

0 个答案:

没有答案