The objective is to create a reminder event via Apple's documentation. So far I have the instance variable created (and implemented in the header file as well).
- (EKReminder *)reminderWithEventStore:(EKEventStore *)eventStore {
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = webTitle;
event.notes = urlField.text;
event.startDate = [[NSDate alloc] init];
event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}
How do I create the reminder by executing the code upon clicking a button within a UIActionSheet? I've tried [self.eventStore:self]; but I'm guessing theres more to it than just that.
Here You are just adding an event to the default Calendar . The event is added , once you call this function.
Simply Create an Object of EKEventStore
EKEventStore *eventStore = [[EKEventStore alloc] init];
and call your function :-
[self reminderWithEventStore:eventStore];
But you are not returning anything in your non-void function :) , but , the function definition is already documented in iOS API version 6 for EKReminder Apple, which is a class Method.
+ (EKReminder *)reminderWithEventStore:(EKEventStore *)eventStore
are you trying to override the above method.
You can simply add a reminder in the calendar using above class method.
First you should be clear of your motive , whether you want to add
1 Event
2 Reminder
3 Calendar.
Related
I am trying to open calendar with specific event, I have added events programmatically and all the IDs of these event are persistent.
This is how i add event
-(IBAction)addEvent:(id)sender{
EKEventStore *store = [[EKEventStore alloc]init];
[store requestAccessToEntityType:EKEntityTypeReminder completion:^(BOOL granted, NSError *error) {
if (!granted) { return; }
EKEvent *event = [EKEvent eventWithEventStore:store];
event.title = #"Demo Title";
NSDateComponents *comps=[[NSDateComponents alloc]init];
[comps setDay:4];
[comps setMonth:10];
[comps setYear:2016];
[comps setHour:12];
[comps setMinute:1];
NSDate *date=[[[NSCalendar alloc]initWithCalendarIdentifier:NSCalendarIdentifierGregorian] dateFromComponents:comps];
_date=date;
event.startDate = date;
event.endDate=date;
event.notes=#"This is event description";
EKAlarm *alarm=[EKAlarm alarmWithAbsoluteDate:date];
[event addAlarm:alarm];
event.calendar = [store defaultCalendarForNewEvents];
NSError *err=nil;
[store saveEvent:event span:EKSpanThisEvent commit:YES error:&err];
}];
}
The event is added successfully and i'm also able to open calendar app but the thing is i can't navigate inside the event detail in calendar
here is how i open calendar
-(IBAction)openCalender:(id)sender{
NSInteger interval = [_date timeIntervalSinceReferenceDate];
NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:#"calshow:%ld?eventid=%#", (long)interval,_eventID]];
NSLog(#"%#",url);
[[UIApplication sharedApplication] openURL:url];
}
What i want is in below screenshot
What i'm getting is
any idea?
To answer my own question, this isn't possible with any of public API
I searched over a year but this is not possible with any public API, but i guess there might be some private API to do this (and probably doing that will get our app rejected).
Widget of calendar app is doing the same what i want to do but it's Apple's API wont allow us to use it. lol
I really don't think there's a way to do this. Even when creating a new calendar event from the default Mail app opens the calendar day view. If this functionality was possible I'm sure they would have at least implemented it in the default mail app.
I want to create three instances of EKEventStore class to store my 3 different events,
EKEventStore *event = [EKEventStore alloc] init];
EKEventStore *event1 = [EKEventStore alloc] init];
EKEventStore *event2 = [EKEventStore alloc] init];
When I checked their eventStoreIdentifier like
NSString *idStr = [event eventStoreIdentifier];
They are actually show same ID and I am unable to separate them.
I have not much worked with Events So anyone can guide me
Thanks.
The EKEventStore is the point of access for calendar and reminder data. You have discovered they all point to the same data. This is because there is only one set of data available to iOS at any time.
To store events requires creating EKEvents and associating them to the event store.
For example:
EKEventStore *theEventStore = [EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:theEventStore];
// Set event properties here.
NSError *error;
[eventStore saveEvent:event span:EKSpanThisEvent error:&error];
I would like to have the actual event, which is synchronised on my calendar app.
The actual event is the event which is happening now.
I would like, at first, to make an app which tells me how much time remains before the end of my event.
The event is my calendar synchronized to my iphone.
In my Main.StoryBoard, I declared a Label:
#property (strong, nonatomic) IBOutlet UILabel *currentEvent;
I declared a EKEventStore:
EKEventStore *store = [[EKEventStore alloc] init];
From now, I know how to create an event, with start date, end date.. but I would like to retrieve the information from my current event, to be able to do: endDate - timeActual;
Next, in my Label, it will be written : 57 minutes before the end of the event.
NSLog(#"%i minutes before the end of the event.", remainTime );
I don't know if I'm clear, tell me if you don't understand what I'm asking?
Thank you for your help! :)
[Update]
I know how to have the identier of my calendar :
EKEventStore *store = [[EKEventStore alloc] init];
store = [[EKEventStore alloc] init];
[store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (!granted)
NSLog(#"Access to store not granted");
}];
NSArray *calendars = [store calendarsForEntityType:EKEntityTypeEvent];
for (EKCalendar *calendar in calendars)
{
NSLog(#"Calendar = %#", calendar.description);
self.currentEvent.text = [NSString stringWithFormat:#"%#", calendar.calendarIdentifier];
}
EKCalendar *myCalendar = calendars[0];
NSLog(#"My Calendar = %#", myCalendar);
EKEvent *actualEvent = [EKEvent eventWithEventStore:store];
I know how to set event on my calendar, but no have events which are in my calendar!
Have you got any ideas ?
In my Application i need to attach(show iphone inbuilt calender) in-built iphone calendar on the UIButton action. More, The text from my UIViewControllers UILabel, I need attach that text in iphones in built calendar as reminder, where user is free to select date according his need.
I had found like EventKIt framework may be useful to me, But i am not sure. And i am also not familiar with EventKit framework.
Just Use this example with EventKit framwork.
-(IBAction)buttonAction:(id)sender
{
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease];
if([eventStore respondsToSelector:#selector(requestAccessToEntityType:completion:)]) {
// iOS 6 and later
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted){
//---- codes here when user allow your app to access theirs' calendar.
[self performCalendarActivity:eventStore];
}else
{
//----- codes here when user NOT allow your app to access the calendar.
}
}];
}
else {
//---- codes here for IOS < 6.0.
[self performCalendarActivity:eventStore];
}
}
-(void)performCalendarActivity:(EKEventStore *)eventStore
{
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = #"EVENT TITLE";
event.startDate = [[NSDate alloc] init];
event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}
Don't forget to import #import <EventKit/EventKit.h> to your view controller.
I want to know if it is possible to create a new calendar for your iphone through an application. I know you can set up event with an app, but can I make another calendar through the app to place all the events too.
EDIT:
IF it is not possible what would be the best work around, make a calendar and event store, and save that information with nscoding? Then retrieve afterwards?
If there is a possibilty to create a new calendar to integrate with the existing calendars, that is what I want to do.
This is how I have done this:
-(NSString*)createCal:(NSString*)myCalId;{
// Instantiate eventstore object
EKEventStore *store = [[EKEventStore alloc] init];
EKSource *localSource = nil;
for (EKSource *source in store.sources)
if (source.sourceType == EKSourceTypeLocal){
localSource = source;
break;
}
//this is you creating your calendar
EKCalendar *cal;
cal = [EKCalendar calendarWithEventStore:store];
cal.title = #"Name of calendar";
cal.source = localSource;
[store saveCalendar:cal commit:YES error:nil];
NSLog(#"cal id = %#", cal.calendarIdentifier);
return cal.calendarIdentifier;}
You will need to import <EventKit/EventKit.h>
This is powerful so you need to be careful and do a lot of verifications for example if the calendar already exist, and so on. Hope this helps.
Looking at the documentation for EventKit, it doesn't seem possible to create new calendars programatically. However, you can get a list of existing calendars and find out the default calendar.
Hope this helps.
You can't use the standard init-Method anymore; it's deprecated. Here the quote from the EKEventStore Class Reference:
"On iOS 5 and later, initialize an event store object with the default init method. On iOS 6 and later, you must request access to an entity type after the event store is initialized with requestAccessToEntityType:completion: for data to return.
On OS X, use initWithAccessToEntityTypes: instead of the default init method. Acceptable entity types are EKEntityMaskEvent for events and EKEntityMaskReminder for reminders."
So if you use iOS6, it's somethin like:
EKEventStore *store = [[EKEventStore alloc] initWithAccessToEntityTypes:completion:];
and
cal = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:store];
I need it for my MacOSX App. So i have to use this:
So in my Case (MacOSX) it's this solution. It's Sparqs code; just modify with the new init instead of the the standard one:
-(NSString*)createCal:(NSString*)myCalId;{
// Instantiate eventstore object
EKEventStore *store = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityMaskEvent];
EKSource *localSource = nil;
for (EKSource *source in store.sources)
if (source.sourceType == EKSourceTypeLocal){
localSource = source;
break;
}
//this is you creating your calendar
EKCalendar *cal;
cal = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:store];
cal.title = #"Name of calendar";
cal.source = localSource;
[store saveCalendar:cal commit:YES error:nil];
NSLog(#"cal id = %#", cal.calendarIdentifier);
return cal.calendarIdentifier;}