Objective c 如何删除UILocalNotification重复间隔?

Objective c 如何删除UILocalNotification重复间隔?,objective-c,uilocalnotification,Objective C,Uilocalnotification,我添加了一个UILocalNotification,重复间隔为一分钟。 如何删除它 - (BOOL)scheduleNotificationOn:(NSDate*) fireDate text:(NSString*) alertText action:(NSString*) alertAction sound:(NSString*) soundfi

我添加了一个UILocalNotification,重复间隔为一分钟。 如何删除它

- (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。。 然后


[[UIApplication sharedApplication]取消所有本地通知]

只需在方法
didLaunchWithOptions
viewDidLoad
下复制它,甚至在下一个
UILocalNotification
代码上复制它。

尝试

notification.repeatInterval = NSCalendarUnit(rawValue: 0)
这个代码是用Swift写的。在objective-c中尝试同样的东西

notification.repeatInterval = NSCalendarUnit(rawValue: 0)