2013-04-26 91 views

回答

0
- (BOOL)scheduleNotificationOn:(NSDate*) fireDate 
          text:(NSString*) alertText 
         action:(NSString*) alertAction 
         sound:(NSString*) soundfileName 
        launchImage:(NSString*) launchImage 
         andInfo:(NSDictionary*) userInfo 
{ 
    UILocalNotification *localNotification = [[UILocalNotification alloc] init]; 
    localNotification.fireDate = fireDate; 
    localNotification.timeZone = [NSTimeZone defaultTimeZone]; 
    localNotification.alertBody = alertText; 
    localNotification.alertAction = alertAction; 
    localNotification.soundName = soundfileName != nil ? soundfileName : UILocalNotificationDefaultSoundName; 
    localNotification.alertLaunchImage = launchImage; 
    localNotification.userInfo = userInfo; 

    for (UILocalNotification *notification in [self allLocalNotifications]) { 
     if ([notification.fireDate timeIntervalSinceDate:localNotification.fireDate] == 0 && 
      [notification.alertBody isEqualToString:localNotification.alertBody] 
      ) { 
      return NO; 
     } 
    } 
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotification]; 
    [localNotification release]; 
    return YES; 
} 
- (NSArray *)allLocalNotifications 
{ 
    return [[UIApplication sharedApplication] scheduledLocalNotifications]; 
} 
- (void)cancelLocalNotification:(UILocalNotification *)notification 
{ 
    [[UIApplication sharedApplication] cancelLocalNotification:notification]; 
} 

- (void)cancelAllLocalNotifications 
{ 
    [[UIApplication sharedApplication] cancelAllLocalNotifications]; 
} 

你应该做的唯一标识符删除通知,如alertBody .. 然后

- (void)cancelLocalNotificationByAlertBody:(NSString *)alertBody 
{ 
    for (UILocalNotification *notification in [self allLocalNotifications]) { 
     if ([notification.alertBody isEqual:alertBodyString]) { 
      [self cancelLocalNotification:notification]; 
      break; 
     } 
    } 
} 
1

[[UIApplication sharedApplication] cancelAllLocalNotifications];

只是复制方法didLaunchWithOptionsviewDidLoad甚至在上您的下一个UILocalNotification代码。

0

尝试用

notification.repeatInterval = NSCalendarUnit(rawValue: 0) 

此代码是斯威夫特。在objective-c中尝试使用相同的东西。