无法在 iPhone 的 eventkit 上保存事件
当我尝试设置开始日期和结束日期时,我不断收到错误消息。我在这里做错了什么?这是我的代码:
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.startDate = date;
newEvent.endDate = date2;
[newEvent setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:newEvent span:EKSpanThisEvent error:&err];
if (err != nil)
{
NSLog(@"error");
}
我当然希望有人可以帮助我解决这个错误,它让我发疯 XD。谢谢。
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.startDate = 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您确定这些日期的格式正确吗?第三个值是月份的日期还是时间的小时?这些可能是无效的,尽管我不确定为什么你没有在记录的错误中看到它......
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...