Opening Reminder application within iOS application? - ios

Is it possible to use iOS Reminder Built in Application within the App I develop?
I dont want to use OPEN URL concept, because it will quit my app an open Reminder App?
Can I please any Custom Reminder App deveoped by iOS SDk , which will create Reminder
in iOS's Reminder Application

There is a reminders API that allows you to create and retrieve reminders.
You'll first have to ask for user permission to do so:
EKEventStore *store = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityMaskReminder];
[store requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
if (granted) {
[self createReminder:store];
}
else {
// :(
}
}];
To create a reminder you could:
- (void)createReminder:(EKEventStore *)store {
//Create a reminder instance
EKReminder *aReminder = [EKReminder reminderWithEventStore:store];
// Set the properties
aReminder.title = #"Remember to do X";
...
// Then save the reminder to the store
NSError *error = nil;
[store saveReminder:aReminder commit:YES error:&error];
// Be responsible
if (error) {
[self rememberToHandleYourErrors:error];
}
}

Related

IOS/Objective-C:EventKit EKReminders compared with EKEvents

I a experimenting with EventKit and am confused by how events compare with reminders.
Do you need to obtain separate permission to access reminders and events?
I know there is such a thing as self.eventStore requestAccessToEntityType:EKEntityTypeReminder and also requestAccessToEntityType:EKEntityTypeEvent
Here are methods for both. But it seems excessive to have to ask for permission for things that are so closely related twice.
-(void)requestAccessToEvents{
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (error == nil) {
// Store the returned granted value.
self.grantedEvents = granted;
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:granted] forKey:#"eventsAccessGranted"];
}
else{
// In case of error, just log its description to the debugger.
NSLog(#"%#", [error localizedDescription]);
}
}];
}
-(void) requestAccessToReminders
{
[self.eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error)
{
if (error == nil) {
// Store the returned granted value.
self.grantedReminders = granted;
[[NSUserDefaults standardUserDefaults] setValue:[NSNumber numberWithBool:granted] forKey:#"remindersAccessGranted"];
}
else{
// In case of error, just log its description to the debugger.
NSLog(#"%#", [error localizedDescription]);
}
if (granted)
{
importEvents * __weak weakSelf = self;
//ensure code will be executed from the main queue
dispatch_async(dispatch_get_main_queue(), ^{
// [weakSelf aMethodToUpdateUIFetchEvents];//method located in viewController
});
}
}];
}
Thanks for any suggestions.
EKEntityTypeEvent is for events that go to the user's calendar.
EKEntityTypeReminder is for reminders that go to the user's reminders.
Each requires its own request for permission. A user might allow access to one but not the other. Ignore that the APIs are similar and related. To the user, they are two completely different things.

How to set a prompt for second time when user has clicked Don't allow for permissions the first time?

I want to add a prompt when user access the calendar second time, when initially user has clicked Don't Allow for the first access permissions for calendar.
// For iOS 6.0 and later
EKEventStore *_eventStore [[EKEventStore alloc] init];
[_eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
// handle access here
}];
EKEventStore *_reminderStore [[EKEventStore alloc] init];
[_reminderStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
// handle access here
}];
This piece of code is for the first time when user is being asked for the permissions, can anyone please tell me, what to do when user has clicked Don't allow after this ?
You can put the second request inside the first request's block.
So it would look like this:
// For iOS 6.0 and later
EKEventStore *_eventStore [[EKEventStore alloc] init];
[_eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
[_eventStore requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
// handle access here
}];
}
}];
Also keep in mind that initializing an EKEventStore is expensive. Try to only use one instance of it. That information and more can be found in the documentation

Access denied for IPad calender in some devices and working fine in some devices

I am facing strange problem, in few IPAD i am not getting prompt to access calender but in few IPAD same code is working fine and promot is displaying to access calender.
Please let me know where i am wrong. I am using Xocde 4.6.3 and running on IPAD with IOS 7.1.1
I am new to objective C, i created one hybrid app and added below code access Calender from my app.
- (void)viewWillAppear:(BOOL)animated
{
// OCT15 - Demo
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
self.eventStore = [[EKEventStore alloc] init];
self.eventsList = [[NSMutableArray alloc] init];
if ([eventStore respondsToSelector:#selector(requestAccessToEntityType:completion:)])
{
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
calendarFlag = #"TRUE";//April16
if (granted)
{
self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];
[eventsList addObjectsFromArray:[self fetchEventsForToday:NULL]];
}
else
{
}
}];
}
else
{
self.defaultCalendar = [self.eventStore defaultCalendarForNewEvents];
[eventsList addObjectsFromArray:[self fetchEventsForToday:NULL]];
}
if (editEventFlag == TRUE)
{
[eventsList addObjectsFromArray:[self fetchEventsForToday:NULL]];
[self eventsdisplay];
}
}
I found out few things, if my ipad is having more than 1 calender in Settings > Mail, Contacts, Calendars. and make them has default everything works fine.
But again if i choose calender(ios one) app won't work.
How to fix this issue?

Programatically add a reminder to the Reminders app

I'm creating a simple note application and I want to implement Reminders. The user would type a note, tap a button and it would set up a reminder in the Reminders app using the text. Is this possible, and if so, how do I do it? I have seen Apple's documentation on EventKit and EKReminders but it has been no help at all.
From the "Calendars and Reminders Programming Guide"? Specifically "Reading and Writing Reminders"
You can create reminders using the reminderWithEventStore: class method. The title and calendar properties are required. The calendar for a reminder is the list with which it is grouped.
Before you create a reminder, ask for permission:
In the .h:
#interface RemindMeViewController : UIViewController
{
EKEventStore *store;
}
and the .m, when you are going to need access to Reminders:
store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeReminder
completion:^(BOOL granted, NSError *error) {
// Handle not being granted permission
}];
To actually add the reminder. This happens asynchronously, so if you try to add a reminder immediately after this, it will fail (crashes the app 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]);
}
}

requestAccessToEntityType - once or every time?

EKEventStore *eventStore = [[UpdateManager sharedUpdateManager] eventStore];
if ([eventStore respondsToSelector:#selector(requestAccessToEntityType:completion:)])
{
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
if (granted)...
I want to ask the user for permission to add an event to his calendar. After it's granted do I need to ask for permission again when I want for example to remove an event (in another session after the app was closed and reopened) or is it just a want time thing?
If it's a one time thing, can I just put it in ViewDidLoad at first lunch just to "get rid of it" ?
You only need to call it once:
BOOL needsToRequestAccessToEventStore = NO; // iOS 5 behavior
EKAuthorizationStatus authorizationStatus = EKAuthorizationStatusAuthorized; // iOS 5 behavior
if ([[EKEventStore class] respondsToSelector:#selector(authorizationStatusForEntityType:)]) {
authorizationStatus = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
needsToRequestAccessToEventStore = (authorizationStatus == EKAuthorizationStatusNotDetermined);
}
if (needsToRequestAccessToEventStore) {
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted) {
dispatch_async(dispatch_get_main_queue(), ^{
// You can use the event store now
});
}
}];
} else if (authorizationStatus == EKAuthorizationStatusAuthorized) {
// You can use the event store now
} else {
// Access denied
}
You shouldn't do that on the first launch, though. Only request access when you need it and that isn't the case just until the user decides to add an event.

Resources