iosekeventekeventstore

How to remove reminder saved as an EKReminder?


I have saved a reminder using EKReminder,now I want to remove this reminder from EKReminder. I have date and time of the reminder to be removed. I tried using NSPRedicate but it didn't work for me.

I am using this code:

EKEventStore *eventStore = [[EKEventStore alloc] init] ;

            EKReminder *reminder = [EKReminder
                                    reminderWithEventStore:eventStore];

            reminder.calendar = [eventStore defaultCalendarForNewReminders];

            EKAlarm *reminderDate = [EKAlarm alarmWithAbsoluteDate:removeReminder];
            [reminder removeAlarm:reminderDate];

            NSError *error = nil;

            [eventStore removeReminder:reminder commit:YES error:&error];

            if (error)
            {
                NSLog(@"error = %@", error);
            }
            else{
                NSLog(@"Reminder removed successfully");
            }

Where removeReminder is my date.

Please suggest me if there is problem with this code.


Solution

  • I found my answer:

    EKEventStore *eventStore = [[EKEventStore alloc] init] ;
                
               
                NSArray *calendarArray = [NSArray arrayWithObject:[eventStore defaultCalendarForNewReminders]];
    
                
                NSPredicate *predicate = [eventStore predicateForRemindersInCalendars:calendarArray];
                
                [eventStore fetchRemindersMatchingPredicate:predicate completion:^(NSArray *reminders)
                 {
                for (EKReminder *reminder  in reminders)
                {
                 //here based on reminder.title i removed the reminder.
    
                 [eventStore removeReminder:reminder commit:YES error:nil];
    
                }