Programmatically add a reminder to the reminder app

I am creating a simple note taking application and I want to implement reminders. The user types a note, presses a button, and sets a reminder in the Reminders application using text. Is this possible, and if so, how can I do this? I saw Apple documentation on EventKit and EKReminders, but that didn't help at all.

+6
source share
1 answer

From "Calendar and Reminder Programming Guide" ? In particular, "Reading and Writing Reminders"

You can create reminders using the reminderWithEventStore: class method. The title and calendar properties are required. A calendar for a reminder is a list with which it is grouped.

Before creating a reminder, ask for permission:

In .h :

 @interface RemindMeViewController : UIViewController { EKEventStore *store; } 

and .m when you need access to reminders:

 store = [[EKEventStore alloc] init]; [store requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) { // Handle not being granted permission }]; 

Actually add a reminder. This happens asynchronously, so if you try to add a reminder right after that, it will not work (application crash in my experience).

 - (IBAction)addReminder:(id)sender { EKReminder *reminder = [EKReminder reminderWithEventStore:store]; [reminder setTitle:@"Buy Bread"]; EKCalendar *defaultReminderList = [store defaultCalendarForNewReminders]; [reminder setCalendar:defaultReminderList]; NSError *error = nil; BOOL success = [store saveReminder:reminder commit:YES error:&error]; if (!success) { NSLog(@"Error saving reminder: %@", [error localizedDescription]); } } 
+16
source

All Articles