Reputation: 42139
I have a GPS
app that registers to run in the background
. I also show a UILocalNotification
when I have finished a process. This correctly shows, and if the app is open, then it also appears in Notification Center
(swipe down from top). But, if I call the UILocalNotification
when my app is in the background, or the screen is locked, I DO get the notification, but it does NOT show up in Notification Center
.
I am correctly registering for notifications in my app delegate (iOS 5 bug workaround):
// Register for notifications
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
Calling the notification:
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.alertBody = msg;
localNotif.alertAction = NSLocalizedString(@"View", nil);
localNotif.soundName = @"alert.caf";
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] presentLocalNotificationNow:localNotif];
[localNotif release];
Is this a bug? Why would it show up in Notification Center
only when my app is open, even though the notification is shown to the user, and not other times?
Upvotes: 1
Views: 3814
Reputation: 5580
Are you also using push notifications? I believe there is no need to call registerForRemoteNotificationTypes:
if you are only using local.
Check Here
Upvotes: 1
Reputation: 6975
have you added the UIBackgroundModes key to your Info.plist file ?
You need to have the UIBackgroundModes Key set to location.
Upvotes: 0
Reputation: 3467
From the look of the code you posted, it does not look like the code would run in the background. It looks like you are trying to present a Local Notification when an even occurs in the background. You can not do this. Local Notifications are meant to be scheduled while the app is running to go off at a later time when the app is not running, and then they will trigger even when the app is closed. You need to use Push Notifications. Check out Apple's documentation here.
EDIT: Is your app enabled for the notification center in settings?
Upvotes: 0