无法在 iPhone 的 eventkit 上保存事件

发布于 2024-11-01 04:28:03 字数 969 浏览 0 评论 0原文

当我尝试设置开始日期和结束日期时,我不断收到错误消息。我在这里做错了什么?这是我的代码:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

烟雨凡馨 2024-11-08 04:28:03
NSString *fechainicio = @"2011-04-13:22:30";
NSString *fechafin = @"2011-04-14:24:00";

您确定这些日期的格式正确吗?第三个值是月份的日期还是时间的小时?这些可能是无效的,尽管我不确定为什么你没有在记录的错误中看到它......

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...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文