I keep getting an error when I try to set my startDate and endDate. What am I doing wrong here? Here's my code:
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *newEvent = [EKEvent eventWithEventStore:eventStore];
NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"yyyy-MM-dd:HH:mm"];
NSString *fechainicio = @"2011-04-13:22:30";
NSString *fechafin = @"2011-04-14:24:00";
NSDate * date = [[NSDate alloc] init];
date = [dateFormatter dateFromString:fechainicio];
NSDate * date2 = [[NSDate alloc] init];
date2 = [dateFormatter dateFromString:fechafin];
[date2 retain];
[date retain];
[fechainicio retain];
[fechafin retain];
newEvent.title = @"title";
newEvent.startDat开发者_JAVA技巧e = date;
newEvent.endDate = date2;
[newEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:newEvent span:EKSpanThisEvent error:&err];
if (err != nil)
{
NSLog(@"error");
}
I surely hope someone can help me with this error, it's driving me crazy XD. Thanks.
NSString *fechainicio = @"2011-04-13:22:30";
NSString *fechafin = @"2011-04-14:24:00";
Are you sure these dates are formatted correctly? Is that third value the date of the month or the hour of the time? These are probably invalid, although I'm not sure why you're not seeing that in the logged error...
精彩评论