Iphone 当应用程序处于后台时,仅iOS徽章本地通知不显示

Iphone 当应用程序处于后台时,仅iOS徽章本地通知不显示,iphone,objective-c,ios,Iphone,Objective C,Ios,编辑:我正在尝试安排仅更新应用程序标记的本地通知。通知不应显示警报框等 当我的应用程序开始使用以下代码时,我正在安排本地通知: NSDate* now = [NSDate date]; NSDate* scheduled = [now dateByAddingTimeInterval:60]; UILocalNotification *localNotif = [[UILocalNotification alloc] init]; if (localNotif == nil) retur

编辑:我正在尝试安排仅更新应用程序标记的本地通知。通知不应显示警报框等

当我的应用程序开始使用以下代码时,我正在安排本地通知:

NSDate* now = [NSDate date];
NSDate* scheduled = [now dateByAddingTimeInterval:60];
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
if (localNotif == nil)
    return;
localNotif.fireDate = scheduled;
localNotif.timeZone = [NSTimeZone systemTimeZone];
localNotif.applicationIconBadgeNumber = 1;

NSLog(@"local notif at %@", scheduled);

[application scheduleLocalNotification:localNotif];
一旦应用程序启动,在fireDate之前,我点击home按钮。 我的申请被放在后台。 在此状态下,我的应用程序不会通过收到通知

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
并且应用程序图标没有用徽章装饰。 我做错什么了吗

谢谢

编辑:发布后,我尝试将UIApplicationExitsOnSuspend添加到我的app Info.plist。当按下home(主页)按钮时,我的应用程序将按预期终止,但在计划日期之后,徽章仍不显示。这可能是因为它是一个仅限徽章的本地通知吗

编辑:向通知中添加警报实际上会显示警报。奇怪的

localNotif.hasAction = YES;
localNotif.alertAction = @"Hoho";
localNotif.alertBody = @"Hihi";

请尝试以下代码:

UILocalNotification* notification = [[UILocalNotification alloc] init]; 
notification.fireDate = [NSDate dateWithTimeIntervalSinceNow:seconds]; 
notification.timeZone = [NSTimeZone systemTimeZone];
localNotif.hasAction = YES;
localNotif.alertAction = @"Hoho";
localNotif.alertBody = @"Hihi";
notification.applicationIconBadgeNumber= dayTomorrow;

[[UIApplication sharedApplication] scheduleLocalNotification:notification]; 
[notification release];
一个好的教程是:


然后尝试本教程中的示例应用程序

谢谢链接。然而,它并没有给出实际问题的答案。本教程使用警报操作和正文显示通知。这对我有用。不需要的是只更新应用程序标记的通知。明天是几天?无论如何,这将显示我不想要的警报。我只想更新应用程序徽章。