Reputation: 289
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.
Upvotes: 0
Views: 3240
Reputation: 401
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;}
Upvotes: 0
Reputation: 823
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.
Upvotes: 3
Reputation: 4977
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.
Upvotes: 0