Reputation: 4441
I have a scenario where the user clicks on a UIButton and the event is automatically added to the my iCal. after importing the #import framework and adding the EKEventEditViewDelegate , how should I have to add the event start date and title etc. All this info is downloaded from the server as text file. Is there any functions that can help me set event date time and title? I shouldn't opening the EventsViewController but do it in the backend. Any suggestions?
Upvotes: 2
Views: 4754
Reputation: 438417
I just set EKEvent
startDate
and endDate
. I don't know what you mean "do it in the backend"...
- (BOOL)createEvent:(NSString *)title
at:(NSString *)location
starting:(NSDate *)startDate
ending:(NSDate *)endDate
withBody:(NSString *)body
andUrl:(NSURL *)url
{
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = title;
event.location = location;
event.startDate = startDate;
event.endDate = endDate;
event.notes = body;
if (url)
event.URL = url;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
EKEventEditViewController *eventViewController = [[EKEventEditViewController alloc] init];
eventViewController.event = event;
eventViewController.eventStore = eventStore;
eventViewController.editViewDelegate = self;
[_viewController presentModalViewController:eventViewController animated:YES];
return TRUE;
}
If you want to convert the date strings from your server into NSDate
objects, NSDateFormatter
generally does the job (assuming the server date text strings are in a well defined format). E.g., it might work something like:
NSString *sampleDate = @"7/23/12 2:30 pm";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"M/d/y h:mm a";
NSDate *date = [formatter dateFromString:sampleDate];
Upvotes: 4