How to makes changes in kal calender to display events from json webservice

528 Views Asked by At

hi am creating an iphone app in which im using calender in order to display events.For this i used kal calender api https://github.com/klazuka/Kal in my project and i need to display events based on start date and end date which are coming from json webservice so where i have to make changes in kal calender project so that i can invoke my start date and end date and display events on that date.Please Provide me the code.Thank you

1

There are 1 best solutions below

1
On

The Holiday Example in the Kal git is a good place to start. it also fetchs the events from JSON and shows it in the KalViewController tableView.

EDIT: I can tell you what i did, i had to show the native calender as well as the JSON events in the Kal calenderView

so i did not change any implementation of Kal for fetching the native events but i did add my own fetching method for server events and combined the two arrays.

here's how i did it, i used the nativeCal example and used the same eventkitDatasource.m as my kal datasource

then, in the KalViewDelegate protocol methood

- (void)didSelectDate:(KalDate *)date 

I sent request to fetch the events from the server for the selected date, on receiving the events array from server, i then add those objects, to an array in the eventkitDatasource.m, and use that array in the

- (NSArray *)eventsFrom:(NSDate *)fromDate to:(NSDate *)toDate

to return events from both native calendar and server events.

here is my implementation of the methood

- (NSArray *)eventsFrom:(NSDate *)fromDate to:(NSDate *)toDate
{
NSMutableArray *matches = [NSMutableArray array];
for (Meeting *meeting in events)
{
    if (IsDateBetweenInclusive(meeting.startDate, fromDate, toDate)){
        [matches addObject:meeting];
    }
}
if([arrServerEvents count]>0){
    [matches addObjectsFromArray:arrServerEvents];
}

return matches;
}

also you can see that here i have created a common Meeting class, which has properties of both Ekevent and my server Events. in changed the EKEvents to my common class object in the

- (void)presentingDatesFrom:(NSDate *)fromDate to:(NSDate *)toDate delegate:(id<KalDataSourceCallbacks>)delegate{

methood, and then added these objects to the native events array of the eventkitDatasource.m.

hope I am clear enough.