Reputation: 14615
When my iOS app exits, it registers a series of local notifications, which update the badge number at specific times. The local notifications do not bring up a popup, they simply update the badge. On my old iPod touch which does not support multitasking, this works perfectly. However, on my multitasking enabled devices, I am experiencing a very strange bug: when I have "exited" the app (i.e. it is still running in the background, but I am doing something else), the local notifications are not firing. Is there any reason why the local notifications would not fire when the app is in the background?
The code to create the local notifications runs in a loop (I create a bunch of them):
UILocalNotification *localNotification = [[UILocalNotification alloc] init];
localNotification.applicationIconBadgeNumber = totalCount; // a number generated earlier in the code
localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.fireDate = endDate; // a date generated earlier
[[UIApplication sharedApplication] scheduleLocalNotification:localNotification];
[localNotification release];
And also I have created the following function in my app delegate, which tells me how many notifications are set up before the app enters the background:
- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"# Notifications: %d", [[[UIApplication sharedApplication] scheduledLocalNotifications] count]);
}
The app constantly tells me that there are 64 notifications (the number that should be set up) when it enters the background.
Upvotes: 0
Views: 2240
Reputation: 799
Swift Version:
func applicationDidEnterBackground(application: UIApplication) {
let notification = UILocalNotification()
notification.alertBody = "App has been entered in background"
notification.alertAction = "open"
notification.fireDate = NSDate()
notification.soundName = UILocalNotificationDefaultSoundName
UIApplication.sharedApplication().scheduleLocalNotification(notification)
}
Upvotes: 0
Reputation: 1057
Check the following from Apple's developers docs: "Each application on a device is limited to 64 scheduled local notifications. The system discards scheduled notifications in excess of this limit, keeping only the 64 notifications that will fire the soonest. Recurring notifications are treated as a single notification."
Could you problem be related to the number of notifications been scheduled?
You can find further information in http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.html
Upvotes: 1
Reputation: 10011
Well @Jason you need to set the alertBody
of the local notification
atleast to show an alert view, thats all there is to it.
Also if you dont wont to show the view option in the alert box then set the hasAction
attribute to NO.
Upvotes: 0