Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i get all calendar and its events from iphone app?

Good Day to you. I have used iCal events in my app. I have add events to iCal and retrieve/delete the events from iCal from my sample iPhone app. Now, i want to show all the calendars what are the calendars user synced in their iPhone(Eg : Google calendar). Then i want to retrieve the events from other calendars except iCal. How can i get all the synced calendars from iPhone? I searched my level best in Google but, can't to get right answer. Can you please help me? Thanks in advance.

like image 586
Yuvaraj.M Avatar asked Jan 17 '12 06:01

Yuvaraj.M


2 Answers

I thank you all for viewing my question. I got the solution for my question. I just retrieved the calendars from EKEventStore and used EKCalendar. Here is my code,

EKEventStore *eventStore = [[[EKEventStore alloc] init] autorelease]; 
EKEvent *events = [EKEvent eventWithEventStore:eventStore];
NSArray *caleandarsArray = [[NSArray alloc] init];
caleandarsArray = [[eventStore calendars] retain]; 

 for (EKCalendar *iCalendars in caleandarsArray) 
 {
     NSLog(@"Calendar Title : %@", iCalendars.title);

 }

This code working for me. Thanks.

like image 51
Yuvaraj.M Avatar answered Nov 06 '22 05:11

Yuvaraj.M


The above code is allocating a new array and pointing the reference to a different array. Isn't this a memory leak?

NSArray *caleandarsArray = [[NSArray alloc] init];
caleandarsArray = [[eventStore caleandarsArray] retain];

This is more optimal.

NSArray *caleandarsArray = [[eventStore caleandarsArray] retain];
like image 39
mac10688 Avatar answered Nov 06 '22 07:11

mac10688