Iphone 无法取消NSLocalNotification并在应用程序内调用NSLocalNotification

Iphone 无法取消NSLocalNotification并在应用程序内调用NSLocalNotification,iphone,ios,xcode,ipad,nsnotificationcenter,Iphone,Ios,Xcode,Ipad,Nsnotificationcenter,我有以下代码,但在通知发出后,我无法取消图标徽章。我应该添加什么代码才能启动应用程序、取消通知和重置图标徽章 另一个问题是,为什么通知只出现在手机的主屏幕上?在应用程序中,通知不会显示。谢谢 display.text=[NSString stringWithFormat:@"%@A",display.text]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Utilities" message:@"Alarm add

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

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

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]; 

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

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
&

要使用此代码取消所有本地通知,请执行以下操作:

[[UIApplication sharedApplication] cancelAllLocalNotifications];
使用以下代码行取消一个本地通知:

[[UIApplication sharedApplication] cancelLocalNotification:theNotification];

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

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
&

要使用此代码取消所有本地通知,请执行以下操作:

[[UIApplication sharedApplication] cancelAllLocalNotifications];
使用以下代码行取消一个本地通知:

[[UIApplication sharedApplication] cancelLocalNotification:theNotification];

谢谢,我刚刚编辑了这个问题。实际上有两个部分。只在应用程序处于后台时才会显示通知。。。因此,它只显示在手机的主屏幕上。。您可以通过以下两种方法取消通知并重置徽章ApplicationIDBecomeActive:和applicationWillEnterForeground:谢谢,我刚刚编辑了这个问题。实际上有两个部分。只在应用程序处于后台时才会显示通知。。。因此,它只显示在手机的主屏幕上。。您可以通过以下两种方法取消通知并重置徽章ApplicationIDBecomeActive:和applicationWillEnterForeground: