海
我有将事件添加到日历的代码,但它没有添加。
-(void)event
{
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = @"Event";
NSDateFormatter *tempFormatter = [[NSDateFormatter alloc]init];
[tempFormatter setDateFormat:@"dd.MM.yyyy HH:mm"];
NSString *dateandtime =[NSString stringWithFormat:@"%@%@%@",datestring,@" ",starttimestring];
NSString *dateandtimeend =[NSString stringWithFormat:@"%@%@%@",datestring,@" ",endtimestring];
event.startDate = [tempFormatter dateFromString:dateandtime];
event.endDate = [tempFormatter dateFromString:dateandtimeend];
[event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -60.0f * 24]];
[event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -15.0f]];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}
从 XML 我得到这种格式的日期和时间:
日期字符串:28.10.2012
开始时间字符串:15:00