2012-01-17 89 views
0

因此,在我的應用程序中,我非常依賴iCal,並且可以使用EventStore添加事件,但只能添加到「defaultCalendarForNewEvents」。我想爲應用中創建的事件製作新的日曆,比如說MyApp日曆,其行爲與「首頁」,「工作」等iCal日曆類似。使用EventStore,我可以創建新的iCal日曆類型嗎?

有沒有辦法做這個progamatically?

現在,我已經試過這樣:

EKEventStore *eventStore = [[EKEventStore alloc] init]; 

NSArray *calendars = [eventStore calendars]; 
BOOL calendarHasBeenInitialized = NO; 
for(NSCalendar *cal in calendars) 
{ 
    if([cal.calendarIdentifier isEqualToString:@"Workout Tracker"]) 
    { 
     calendarHasBeenInitialized = YES; 
    } 
} 
if(!calendarHasBeenInitialized) 
{ 
    NSString *string = [[NSString alloc] initWithString:@"Workout Tracker"]; 
    NSCalendar *workoutCalendar = (__bridge NSCalendar *)(CFCalendarCreateWithIdentifier(kCFAllocatorSystemDefault, (__bridge CFStringRef)string)); 
    EKCalendar *ekcalendar = (EKCalendar *)workoutCalendar; 
    NSError *error; 
    [eventStore saveCalendar:ekcalendar commit:YES error:&error]; 
} 

這就是所謂的在我的應用程序代表,其中如果日曆不是日曆陣中,我嘗試創建它。但是,這不起作用。

任何幫助,將不勝感激!

回答

0

根據文檔,使用EKCalendar的+calendarWithEventStore:方法在您指定的事件存儲中創建新日曆。我期望它會這樣:

EKCalendar *newCalendar = [EKCalendar calendarWithEventStore:eventStore]; 
+0

雖然這確實看起來會創建一個新的日曆,但我嘗試過使用它,然後將我的活動日曆設置爲我創建的這個新日曆。但是,這並不奏效,因爲當我嘗試將事件保存到eventStore時出現錯誤。 – BHendricks 2012-01-17 07:26:52

相關問題