- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我正在 ios 6 中使用 eventkit 框架开发日历应用程序。我正在尝试使用 [self.store respondsToSelector:@selector(requestAccessToEntityType:completion:)] 获得许可
方法并获得访问日历的权限后,我尝试使用 EKSourceTypeLocal 源创建带有标识符的新日历,并将事件添加到新创建的日历中。我在这里遇到的问题是,当我尝试在 iPhone 4s 中运行该应用程序时,它显示“日历没有来源”的错误,并且它不保存我的日历,因此没有事件被添加到日历中。我不知道我在这里做错了什么。请指导我解决这个问题。
我在下面发布我的代码
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSLog(@"in view did load method");
// For iOS 6.0 and later
self.store = [[EKEventStore alloc] init];
if([self.store respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
[self.store requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
// handle access here
dispatch_async(dispatch_get_main_queue(), ^{
if (granted) {
NSLog(@"permission granted");
EKCalendar *myCalendar;
EKSource *myLocalSource = nil;
for (EKSource *calendarSource in self.store.sources) {
if (calendarSource.sourceType == EKSourceTypeLocal) {
myLocalSource = calendarSource;
break;
}
}
if (!myLocalSource)
return;
NSString *mycalIndentifier = [[NSUserDefaults standardUserDefaults] valueForKey:@"my_calendar_identifier"];
if (mycalIndentifier == NULL) {
// Create a new calendar of type Local... save and commit
myCalendar = [EKCalendar calendarForEntityType:EKEntityTypeEvent eventStore:self.store];
myCalendar.title = @"New_Calendar";
myCalendar.source = myLocalSource;
NSString *calendarIdentifier = myCalendar.calendarIdentifier;
NSError *error = nil;
[_store saveCalendar:myCalendar commit:YES error:&error];
if (!error) {
NSLog(@"created, saved, and commited my calendar with id %@", myCalendar.calendarIdentifier);
[[NSUserDefaults standardUserDefaults] setObject:calendarIdentifier forKey:@"my_calendar_identifier"];
} else {
NSLog(@"an error occured when creating the calendar = %@", error.description);
error = nil;
}
//create an event
// Create a new event... save and commit
EKEvent *myEvent = [EKEvent eventWithEventStore:_store];
myEvent.allDay = NO;
myEvent.startDate = [NSDate date];
myEvent.endDate = [NSDate date];
myEvent.title = @"Birthday";
myEvent.calendar = myCalendar;
[_store saveEvent:myEvent span:EKSpanThisEvent commit:YES error:&error];
if (!error) {
NSLog(@"the event saved and committed correctly with identifier %@", myEvent.eventIdentifier);
} else {
NSLog(@"there was an error saving and committing the event");
error = nil;
}
EKEvent *savedEvent = [_store eventWithIdentifier:myEvent.eventIdentifier];
NSLog(@"saved event description: %@",savedEvent);
}
else{
myCalendar = [_store calendarWithIdentifier:mycalIndentifier];
}
}
else if(!granted){
NSLog(@"Permission not granted");
}
else{
NSLog(@"error = %@", error.localizedDescription);
}
});
}];
}
}
this is the error I am getting :
Predicate call to calendar daemon failed: Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"
not saved = Error Domain=EKErrorDomain Code=14 "Calendar has no source" UserInfo=0x1d5f6950 {NSLocalizedDescription=Calendar has no source}
更新: 我使用此链接解决了问题 try it
最佳答案
问题似乎是在启用 iCloud 时隐藏了本地日历,因此您需要处理这两种情况(启用和未启用 iCloud)。
请参阅此答案以获得可行的解决方案:https://stackoverflow.com/a/15980556/72176
关于iphone - 在 ios 6 中使用 EventKit 创建新日历时出现 "calendar has no source"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17950504/
也许是一个愚蠢的问题,但我有一个在 Java 文档中没有找到的问题。 Calendar.get(Calendar.DAY_OF_WEEK) 的值是否会根据 Calendar.getFirstDayOf
假设以下代码在 2009 年 8 月 22 日(星期六)执行 Calendar c = Calendar.getInstance(); c.set(Calendar.DAY_OF_WEEK
我正在使用以下代码检查所选月份是否为一月: if (calendar.get(Calendar.MONTH) == Calendar.JANUARY) { ... } 这给了我一个 lint
我有两个 Calendar 变量,分别命名为 calendar1 和 calendar2 其中存储了一些日历值。 我想比较这些变量的 MINUTE 值。 我找到了两种方法,但我想知道有什么区别以及哪一
根据文档 ( here ),Google 提供了一些相同的范围: https://www.googleapis.com/auth/calendar读/写访问到日历 https://www.google
我想问一下,是否可以在不调用 Google 日历 API(需要互联网连接)或启动 native 日历 Activity (不需要)的情况下添加日历事件?只需将日历事件添加到设备 native 日历中(
我们可以从谷歌日历设置中获取工作时间数据吗?我已经了解了日历的 API : https://developers.google.com/calendar/v3/reference/settings/g
我正在尝试使用 Exchange Web 服务访问日历数据,但我似乎无法弄清楚如何访问其他用户共享的日历(当它不是他们的默认日历时)。假设我公司的另一个用户创建了一个共享日历并与我共享,我什至找不到日
我对 Java/Android 中的日期比较有点困惑 DateFormat df = new SimpleDateFormat("dd/MM/yy HH:mm");
我正在使用Google的Calendar API,但遇到了一个问题。当我设置要插入的事件的dateTime时,需要设置小时偏移量,但是由于o DST的原因,它需要一个小时。我可以为日历设置一个属性,以
在Google日历的常规网络用户界面中,当我添加事件时,可以选择将其设置为“提醒”,而不是“事件”。 我正在尝试使用Python API进行复制,但是似乎找不到有关如何执行该操作的信息。我找到的所有文
我们可以使用这个link通过参数向Google日历添加新事件 https://www.google.com/calendar/render? action=TEMPLATE& text=EventNa
除了在纪元显式设置它们之外,是否有任何现有方法可以使用日历 API 来获取填充纪元时间的日历?我所能做的就是获取当前时间。 最佳答案 没有预定义的构造函数或工厂方法来执行此操作,但它相当简单: Cal
我试图在我的应用程序上次更新时显示在 TextView 中(例如,“上次更新时间为 12:13”)。我正在尝试使用 Calendar 实例,我认为我理解正确,但我似乎遇到了麻烦. 我知道要获取一个实例
这个问题在这里已经有了答案: Calendar.before(Object when), why Object? (3 个答案) 关闭 8 年前。 我遇到了问题,因为我试图将日期传递给 Calend
在IOS5上使用获取所有日历时 EKEventStore *eventStore = [[EKEventStore alloc] init]; NSArray * calendars = [event
当我运行以下代码时: int year = 2017; int month = 7; int dayOfMonth = 10; Calendar dateOfBirth = new Gregorian
要么我不理解方法 getActualMaximum(int) 或字段 WEEK_OF_YEAR,要么涉及 Sun 错误(或所有三个)...有人可以向我解释为什么(至少在德语语言环境中...) 以下代码
我正在检查我几年前写的代码。然后我意识到 Android Studio 在 Calendar.AM 处给出了注释,它说它必须是 Calendar.SUNDAY、Calendar.MONDAY 之一等等
我需要将给定日期复制 100 次(我无法通过引用传递)。我想知道以下两个中哪个是更好的选择 newTime=Calendar.getInstance().setTime(originalDate);
我是一名优秀的程序员,十分优秀!