我有一个GPS
应用程序注册运行在background
。当我完成一个过程时,我还会显示一个UILocalNotification
。这正确显示,如果应用程序是打开的,那么它也出现在Notification Center
(从顶部向下滑动)。但是,如果当我的应用程序处于后台或屏幕被锁定时拨打UILocalNotification
,我会收到通知,但不会显示在Notification Center
中。UILocalNotification没有显示在通知中心,当应用程序在后台
我正确地注册在我的应用程序委托的通知(iOS 5的错误解决):
// Register for notifications
[[UIApplication sharedApplication]registerForRemoteNotificationTypes:
UIRemoteNotificationTypeBadge |
UIRemoteNotificationTypeAlert |
UIRemoteNotificationTypeSound];
调用通知:
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];
这是一个错误?为什么只有当我的应用程序处于打开状态时才会在Notification Center
中显示,即使通知显示给用户,而不是其他时间?
不,代码在后台完美工作。它已被广泛测试。本地通知即使在后台工作,也不会在通知中心显示。 – 2012-01-09 02:16:16
您的应用程序是否在设置中为通知中心启用了应用程序? – DGund 2012-01-09 03:02:25
是的。它显示在通知中心,如果应用程序是开放的。在后台时只显示通知警报。 – 2012-01-09 03:20:49