提问人:zpasternack 提问时间:3/4/2012 最后编辑:zpasternack 更新时间:3/5/2012 访问量:497
日历商店:如何区分事件日历和任务日历?
Calendar Store: how to distinguish event calendar from task calendar?
问:
我正在开发一个具有提醒组件的应用程序。我正在使用日历商店获取日历列表,并希望用户选择要向其添加任务的日历。问题是,CalCalendar 似乎没有区分事件日历和任务日历。
NSArray* calendars = [[CalCalendarStore defaultCalendarStore] calendars];
for( CalCalendar* aCalendar in calendars ) {
if( aCalendar.isEditable ) {
NSLog( @"editable calendar: %@", aCalendar );
}
}
这将输出:
editable calendar: CalCalendar <0x6e04d10> {UID = 8AA8FFAD-D781-47F7-9231-CF66E1753983; title = Work; notes = (null); color = NSCalibratedRGBColorSpace 0.054902 0.380392 0.72549 1; type = CalDAV; editable = 1}
editable calendar: CalCalendar <0x6e05000> {UID = A7F4A1B2-D1CF-4A20-9F84-CD1A1E99773E; title = Home; notes = ; color = NSCalibratedRGBColorSpace 0.72549 0.054902 0.156863 1; type = CalDAV; editable = 1}
editable calendar: CalCalendar <0x6e050f0> {UID = 43B14D2A-9976-461C-8EFE-5FA029381828; title = Personal; notes = (null); color = NSCalibratedRGBColorSpace 0.901961 0.784314 0 1; type = CalDAV; editable = 1}
editable calendar: CalCalendar <0x6e05140> {UID = F42EC365-20AC-4251-B45E-FB7F169928F0; title = Mac; notes = (null); color = NSCalibratedRGBColorSpace 0.054902 0.380392 0.72549 1; type = Local; editable = 1}
editable calendar: CalCalendar <0x6e05190> {UID = FF771FF9-3969-4001-BBA4-9B7B00E80291; title = Cloud 2; notes = (null); color = NSCalibratedRGBColorSpace 0.054902 0.380392 0.72549 1; type = CalDAV; editable = 1}
editable calendar: CalCalendar <0x6e051e0> {UID = 40234537-869C-4CC2-89B9-DD4F7D36C169; title = Groceries; notes = ; color = NSCalibratedRGBColorSpace 0.443137 0.101961 0.462745 1; type = CalDAV; editable = 1}
我知道前 2 个是事件日历,后 4 个是任务列表。而且,iCal 绝对知道其中的区别,因为它只显示事件的事件日历和任务的任务日历。
但是似乎没有办法通过日历存储 API 以编程方式确定这一点,除非我遗漏了什么。
更新:我发现我不是唯一一个注意到这一点的人,因为我发现 rdar://10377730。我刚刚提交了自己的报告,rdar://10980542
答:
1赞
zpasternack
3/5/2012
#1
我对此不是很满意,但我现在使用的解决方法是简单地尝试在每个日历中创建一个任务。如果您尝试在事件日历中创建任务,则会出现错误。它看起来有点像:
- (BOOL) isCalendarAUsableTaskList:(CalCalendar*)aCalendar
{
if( !aCalendar.isEditable ) return NO;
// Try to make a task here.
CalTask* newTask = [CalTask task];
newTask.calendar = aCalendar;
newTask.title = @"Test Item";
NSError* anError = nil;
if( ![[CalCalendarStore defaultCalendarStore] saveTask:newTask error:&anError] ) {
// Couldn't make a task, this calendar is no bueno.
NSLog( @"Error saving task to calendar %@ (%@)", aCalendar.title, [anError localizedDescription] );
return NO;
}
// Created a task. Now clean up on our way out.
NSLog( @"Saved task to calendar %@", aCalendar.title );
[[CalCalendarStore defaultCalendarStore] removeTask:newTask error:nil];
return YES;
}
评论