1

我有以下代码,但通知出来后,我无法取消图标徽章。为了启动应用程序、取消通知和重置图标徽章,我应该添加什么代码?

另一个问题是为什么通知只出现在手机的主屏幕上?在应用程序中,通知不会显示。谢谢。

display.text=[NSString stringWithFormat:@"%@A",display.text];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Utilities" message:@"Alarm added" delegate:self cancelButtonTitle:@"Done" otherButtonTitles:nil];
    // optional - add more buttons:

    [alert show];

    UILocalNotification *localNotification = [[UILocalNotification alloc] init]; //Create the localNotification object

    NSDate *date = [NSDate date];

    // Add one minute to the current time
    NSDate *dateToFire = [date dateByAddingTimeInterval:20];

    // Set the fire date/time
    [localNotification setFireDate:dateToFire];
    [localNotification setTimeZone:[NSTimeZone defaultTimeZone]];


    [localNotification setAlertAction:@"Done"]; 
    [localNotification setAlertBody:@"(A)"]; 
    [localNotification setHasAction: YES]; 
    [localNotification setSoundName:UILocalNotificationDefaultSoundName];

    [localNotification setApplicationIconBadgeNumber:[[UIApplication sharedApplication] applicationIconBadgeNumber]+1]; 

    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
4

1 回答 1

1

要删除徽章编号,您可以使用此

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

&

使用此代码取消所有本地通知:

[[UIApplication sharedApplication] cancelAllLocalNotifications];

使用这行代码取消一个本地通知:

[[UIApplication sharedApplication] cancelLocalNotification:theNotification];
于 2013-03-11T18:32:10.983 回答