I want to add an event but the event is added in all the days. If I add an event which has a last date after 10 days, then the event is added today and all the days between today and 10 days from now. I want to just add the event at the end date, not between these days. How can I do this?
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = appDelegate.Name;
event.startDate = [[NSDate alloc] init];
event.endDate = appDelegate.Date_iCal;
//event.allDay = NO;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
you have to specify the correct start date.
Right now you do this
event.startDate = [[NSDate alloc] init]; // today
event.endDate = appDelegate.Date_iCal; // in the future
and this will obviously add an event that starts now and ends somewhere in the future.
I don't know anything about your event, so you have to figure out the start and end of it on your own.
Related
I'm developing an app in which when user add any event as his favorite, I'm adding that event to iCal but how do i remove that event from iCal if user removes that particular event from his favorite.?
Here is my code:
NSDate *date = [NSDate dateWithTimeIntervalSince1970:[[self.parentDetailArray valueForKey:#"start_time_num"] intValue]];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc]init];
[dateformatter setLocale:[NSLocale currentLocale]];
[dateformatter setDateFormat:#"dd-MM-yyyy"];
NSString *dateString=[dateformatter stringFromDate:date];
EKEventStore *eventStore = [[EKEventStore alloc] init];
if([eventStore respondsToSelector:#selector(requestAccessToEntityType:completion:)])
{
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
if (granted){
//---- codes here when user allow your app to access theirs' calendar.
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = title;
event.startDate = date;
event.endDate = [[NSDate alloc] initWithTimeInterval:1000 sinceDate:event.startDate];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
// Here I'm trying to get the identifier of that event but m getting only (null)
self.str = [[NSString alloc] initWithFormat:#"%#", event.eventIdentifier];
[self.arrayofEventId addObject:self.str];
//[self performCalendarActivity:eventStore];
}else
{
//----- codes here when user NOT allow your app to access the calendar.
}
}];
}
else {
//---- codes here for IOS < 6.0.
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = #"Testing for calendar";
event.startDate = [[NSDate alloc] init];
NSLog(#"%#",event.startDate);
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
//[self performCalendarActivity:eventStore];
}
How do i get the event identifier n remove that particular event from iCal. any help would be appreciated.
You could write all app generated event ID's to file and then load them back up next time the app loads. This way you can keep track of which events your app created. Then you may want to try this method:
- (BOOL)removeEvent:(EKEvent *)event span:(EKSpan)span commit:(BOOL)commit error:(NSError **)error
Save with this:
NSString *id = [[NSString alloc] initWithFormat:#"%#", event.eventIdentifier];
Remove with this:
EKEvent *event = [eventStore eventWithIdentifier:id];
NSError *error = nil;
[eventStore removeEvent:event span:EKSpanThisEvent error:&error];
Apple has documentation on the EKEventStore here.
Can anybody tell me how to make a repeating (weekly,daily,monthly) event for iOS Calendar events. My current implementation is something like this:
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = [cellValue objectForKey:#"ZEVENTNAME"];
event.notes = [cellValue objectForKey:#"ZEVENTDESCRIPTION"];
event.location = [cellValue objectForKey:#"ZLOCAITONname"];
NSString * dateStart =[cellValue objectForKey:#"ZEVENTSTARTDATE"];
NSString * dateEnd =[cellValue objectForKey:#"ZEVENTENDDATE"];
NSDateFormatter *_formatter=[[NSDateFormatter alloc]init];
[_formatter setDateFormat:#"yyyyMMdd"];
NSDate *sDate = [_formatter dateFromString:dateStart];
NSDate *eDate = [_formatter dateFromString:dateEnd];
[_formatter setDateFormat:#"MM/dd/yyyy"];
event.startDate = sDate;
event.endDate = eDate;
event.calendar = [eventStore defaultCalendarForNewEvents];
NSError *error;
[eventStore saveEvent:event span:EKSpanThisEvent error:&error];
I have gone through developer help from apple but couldn't get the way how to implement.
Thanks
I Want to add my events that is in my server into ical using eventkit. Can I subscribe to a url programatically so that all the event can be sync in ical app automatically.
Synchronization is done from your side (Inside objective "c"). You need to fetching all events from server after hitting appropriate URL.
Parse it and save single event with the help of below method:
-(void)addingEvents{
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = <<Event Title>>;
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: #"yyyy-MM-dd hh:mma"];
[dateFormatter setTimeZone:[NSTimeZone systemTimeZone]];
NSString *strDate = [dateFormatter stringFromDate:<<Your event date>>];
NSDate *startDate = [dateFormatter dateFromString:strDate];
[dateFormatter release];
event.startDate = [[NSDate alloc] initWithTimeInterval:0 sinceDate:startDate];
event.endDate = [[NSDate alloc] initWithTimeInterval:600 sinceDate:event.startDate];
NSArray *alertArray = [NSArray arrayWithObject:[EKAlarm alarmWithRelativeOffset:-300]];
event.alarms = alertArray;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
if (err) {
NSLog(#"Error occured : %#",[err localizedDescription]);
}
[eventStore release];
}
Was looking at some code and it looks to be leaking memory. And I'm not sure should I clean this up? Or is it ok?
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
I would have guessed this is an autorelease since its a connivence method.
But when i read
event.startDate = [[NSDate alloc] init];
I see an alloc and an init, so I get nervous about wondering will it be leaking.
Full block of code below:
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = #"Test Event for Code Demo";
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];
[eventStore release];
Thanks,
-Code
I don't think the properties startDate and endDate need to be alloc'd and init'd. You are creating an autoreleased object with your current code.
EKEvent *event = [EKEvent eventWithEventStore:eventStore]; // autoreleased this way
To fill your dates and properties, try an alternate method to fill.
event.startDate = [NSDate date];
event.endDate = [NSDate dateWithTimeInterval:600 sinceDate:event.startDate];
Now you just need to release eventStore like you are currently doing. Hope this helps.
If you are using EKEventViewController, Apple documentation says following:
#property(nonatomic, retain) EKEvent *event
Discussion
This property must be set before the view is displayed.
EKEventViewController Documentation
I am using the following code to create an event within the iPhone's calendar;
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = #"DHSB Assignment: %#", Assignment1.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];
[EKEventStore release];
NSLog(#"Successfully added '%#' to the calendar", Assignment1.text);
Why is this saving an event with the name "DHSB Assignment: %#" rather than "DHSB Assignment: Example Text"?
Thank you.
event.title = [NSString stringWithFormat:#"DHSB Assignment: %#", Assignment1.text];
Your current code is equivalent to
[event setTitle:#"DHSB Assignment: %#"];
[Assignment1 text];
…which is valid, so it compiles and runs fine even though it isn’t doing what you want.