2
모든 iCal 이벤트를 isc 파일로 내보내는 응용 프로그램을 만들어야합니다. 어떻게 할 수 있습니까? 코코아 응용 프로그램, 명령 줄 도구 또는 AppleScript 응용 프로그램을 사용하여 .... AppleScript 응용 프로그램에서 CalendarStore Framework를 사용하여이 작업을 수행하려고합니다. 모든 이벤트를 가져올 수 있지만 ics 파일에 저장하는 방법은 무엇입니까 ??iCal 이벤트를 oics의 .ics 파일로 내보내기
NSFileManager *fileManager = [[NSFileManager alloc] init];
// /Users/username/Library/Calendars
NSError *err;
NSArray *usersFolder = [fileManager contentsOfDirectoryAtPath:@"/Users" error:&err];
for (NSString *dirElement in usersFolder) {
// NSLog(@"users folder : %@",dirElement);
NSString *userCalendarPath = [NSString stringWithFormat:@"/Users/%@/Library/Calendars",dirElement];
NSArray *contentCalendarDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:userCalendarPath error:nil];
NSArray *calendarFolders = [contentCalendarDirectory filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.calendar'"]];
NSMutableArray *calendarNames= [[NSMutableArray alloc] init];
for(NSString *calendarFolder in calendarFolders)
{
// NSLog(@"calendar folder %@/%@",userCalendarPath,calendarFolder);
NSString * fullCalendarInfoPath = [NSString stringWithFormat:@"%@/%@/Info.plist",userCalendarPath,calendarFolder];
NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile: fullCalendarInfoPath];
NSString * eventsDirectory = [NSString stringWithFormat:@"%@/%@/Events",userCalendarPath,calendarFolder];
NSArray *contentEventsDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:eventsDirectory error:nil];
NSArray *events = [contentEventsDirectory filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"self ENDSWITH '.ics'"]];
for(NSString* eventName in events)
{
NSString * eventPath = [[NSString alloc] initWithFormat:@"%@/%@/Events/%@",userCalendarPath,calendarFolder,eventName];
//this array contain all ics paths...
//to read file content:
//NSString *eventContent = [[NSString alloc] initWithContentsOfFile:eventPath encoding:NSUTF8StringEncoding error:nil];
[eventsPath addObject:eventPath];
}
NSString* calendarTitle = [dict objectForKey: @"Title"];
[calendarNames addObject:[NSString stringWithFormat:@"%@ (%lu events)",calendarTitle,[events count]]];
}
if(calendarNames.count>0)
{
NSDictionary *userCalendars = [NSDictionary dictionaryWithObjectsAndKeys:dirElement,@"parent",calendarNames,@"children", nil];
[dataCalendars addObject:userCalendars];
}
}
: 지금 내가 CalendareStore 프레임 워크를 사용하지 않는 ... 문제를 해결
- (IBAction)btnSelector:(id)sender {
CalCalendarStore *calendarStore = [CalCalendarStore defaultCalendarStore];
NSDate *startDate=[[NSDate alloc] init];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
startDate=[formatter dateFromString:@"2010-01-01 00:00:00"];
NSDate *endDate=[[NSDate alloc] init];
endDate=[formatter dateFromString:@"2050-01-01 00:00:00"];
NSArray *calendars = [calendarStore calendars];
NSPredicate *allEventsPredicate = [CalCalendarStore eventPredicateWithStartDate:startDate endDate:endDate calendars:[calendarStore calendars]];
NSArray *events = [calendarStore eventsWithPredicate:allEventsPredicate];
for(CalEvent *event in events)
{
//here i must save event to file...
NSLog(@"%@",event);
}
for (CalCalendar *calendar in calendars) {
self.lblNotification.title=[NSString stringWithFormat:@"%@ %@",self.lblNotification.title,calendar.title];
}
}