I got local notifications working for my iOS project some time last year before putting it aside, but when I came back a few weeks ago I noticed that they no longer worked. I've dug around for a few days and I'm completely stumped. The badge still updates properly with a background fetch, but the notification alert is no longer sent. Here's a minimal setup of what I have for testing.
AppDelegate:
func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
application.setMinimumBackgroundFetchInterval(UIApplicationBackgroundFetchIntervalMinimum)
application.registerUserNotificationSettings(UIUserNotificationSettings(forTypes: [.Badge, .Alert], categories: nil))
return true
}
func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
let localNotification = UILocalNotification()
localNotification.alertAction = "Message"
application.presentLocalNotificationNow(localNotification)
completionHandler(.NoData)
}
Things I've tried:
Setup:
Did something change in the API that I missed, or is there some error in what I'm doing? Thanks for any help!
UILocalNotification requires that alertBody
be set in order to display. So having the following works:
func application(application: UIApplication, performFetchWithCompletionHandler completionHandler: (UIBackgroundFetchResult) -> Void) {
let localNotification = UILocalNotification()
localNotification.alertBody = "You have a notification"
localNotification.alertAction = "Message"
application.presentLocalNotificationNow(localNotification)
completionHandler(.NoData)
}