gpt4 book ai didi

ios - 如何修复 EKErrorDomain Code=1“未设置日历

转载 作者:行者123 更新时间:2023-11-30 10:51:27 31 4
gpt4 key购买 nike

我想为iPhone日历创建一个日历条目,我尝试了以下代码

        EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = self.selectedPost.postTitle;
event.notes = self.selectedPost.postContent;
event.startDate = self.selectedPost.startDate;
event.endDate = self.selectedPost.endDate;

EKCalendar *targetCalendar = nil;
targetCalendar = [eventStore defaultCalendarForNewEvents];
NSLog(@"%@",targetCalendar);
[event setCalendar:targetCalendar];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
UIAlertView *alert = nil;
NSLog(@"err %@",err);
if (err) {
alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[err localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
}
else{
alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Added to calender" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
}

[alert show];

但结果是

2013-01-15 22:31:34.682 Project[40863:907] defaultCalendarForNewEvents failed: Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"
2013-01-15 22:31:34.683 Project[40863:907] (null)
2013-01-15 22:31:34.690 Project[40863:907] err Error Domain=EKErrorDomain Code=1 "No calendar has been set." UserInfo=0x1d535ba0 {NSLocalizedDescription=No calendar has been set.}

我知道这是因为

[eventStore defaultCalendarForNewEvents];

返回空值。我努力了 [eventStore calendarWithIdentifier:event.calendarItemIdentifier];和其他一些代码但结果相同如何解决这个问题有什么想法

最佳答案

如果是在 iOS 6.0 或更高版本上,您必须首先请求访问用户的日历,然后 EventKit 将使用方法 -[EKEventStore requestAccessToEntityType:completion:] 将它们交给您。

查看 Calendar and Reminders Programming Guide 中给出的示例

关于ios - 如何修复 EKErrorDomain Code=1“未设置日历,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54434120/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com