我正在尝试在 iCal 中创建一个新日历。现在我可以创建一个带有某个名称的新日历。但我的问题是当我尝试创建本地日历时,我无法在日历列表中看到它。有人对此有任何想法吗?我尝试过使用所有类型的资源,但无法找到确切的解决方案。
先感谢您。
NSMutableArray *arrAlarm = [[NSMutableArray alloc]init];
EKAlarm *alarm1 = [EKAlarm alarmWithRelativeOffset:3600];
EKAlarm *alarm2 = [EKAlarm alarmWithRelativeOffset:-3600]; //86400 1 day
[arrAlarm addObject:alarm1];
[arrAlarm addObject:alarm2];
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *ekevent = [EKEvent eventWithEventStore:eventStore];
ekevent.title = strname;
NSLog(@"%@",ekevent.startDate);
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"EEE MMM d,yyyy"];
NSDate *date = [dateFormatter dateFromString:strdate];
// Convert to new Date Format
[dateFormatter setDateFormat:@"YYYY-MM-DD HH:MM:SS ±HHMM"];
NSString *newDate = [dateFormatter stringFromDate:date];
// dateFormatter = [[[NSDateFormatter alloc] init] autorelease];
// [dateFormatter setLocale:[[[NSLocale alloc] initWithLocaleIdentifier:@"en_US_POSIX"] autorelease]];
[dateFormatter setDateFormat:@"hh:mm a"];
NSDate* firstDate = [dateFormatter dateFromString:time];
NSDate* secondDate = [dateFormatter dateFromString:endtime];
NSTimeInterval timeDifference = [secondDate timeIntervalSinceDate:firstDate];
// Convert to new Date Format
[dateFormatter setDateFormat:@"HH:MM"];
NSString *t11 = [dateFormatter stringFromDate:firstDate];
NSString *t12 = [dateFormatter stringFromDate:secondDate];
NSDate *dt1 = [dateFormatter dateFromString:t11];
NSDate *dt2 = [dateFormatter dateFromString:t12];
NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"hh"];
NSString *hourstring = [NSString stringWithFormat:@"%@",
[df stringFromDate:dt1]];
[df setDateFormat:@"mm"];
NSString *minstring = [NSString stringWithFormat:@"%@",
[df stringFromDate:dt1]];
[df release];
NSCalendar *gregorian = [[NSCalendar alloc] initWithCalendarIdentifier: NSGregorianCalendar];
NSDateComponents *components = [gregorian components: NSUIntegerMax fromDate: date];
[components setHour: [hourstring intValue]];
[components setMinute: [minstring intValue]];
[components setSecond: 00];
// NSDate *newDate = [gregorian dateFromComponents: components];
[gregorian release];
ekevent.startDate = date;
ekevent.endDate = [[NSDate alloc] initWithTimeInterval:timeDifference sinceDate:date];
[ekevent setCalendar:[eventStore defaultCalendarForNewEvents]];
ekevent.alarms = arrAlarm;
[arrAlarm release];
NSError *err;
[eventStore saveEvent:ekevent span:EKSpanThisEvent error:&err];
试试这个代码,你会得到想要的结果。