2013-03-11 25 views
1

我有以下代碼,但通知出來後,我無法取消圖標徽章。我應該添加什麼代碼才能啓動應用程序,取消通知並重置圖標徽章?無法取消NSLocalNotification並在應用程序內調用NSLocalNotification

另一個問題是爲什麼通知只出現在手機的主屏幕上?在應用程序中,通知不會顯示。謝謝。

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

回答

1

要刪除的證件號碼,你可以使用這個

[UIApplication sharedApplication].applicationIconBadgeNumber = 0; 

&

取消所有本地通知與此代碼:

[[UIApplication sharedApplication] cancelAllLocalNotifications]; 

取消一個本地通知本代碼行:

[[UIApplication sharedApplication] cancelLocalNotification:theNotification]; 
+0

謝謝,我剛剛編輯了這個問題。其實有兩個部分。 – Clarence 2013-03-11 18:36:39

+0

只有當您的應用程序處於後臺時纔會顯示通知...因此它僅在手機的主屏幕中顯示.. 並且您可以取消您的通知並重置這兩種方法中的徽章 applicationDidBecomeActive:和 applicationWillEnterForeground: – 2013-03-11 18:42:49

相關問題