海兰
我有这个代码用于向日历添加事件,但它没有添加.
-(void)event
{
EKEventStore *eventStore = [[EKEventStore alloc] init];
EKEvent *event = [EKEvent eventWithEventStore:eventStore];
event.title = @"Event";
NSDateFormatter *tempFormatter = [[NSDateFormatter alloc]init];
[tempFormatter setDateFormat:@"dd.MM.yyyy HH:mm"];
NSString *dateandtime =[NSString stringWithFormat:@"%@%@%@",datestring,@" ",starttimestring];
NSString *dateandtimeend =[NSString stringWithFormat:@"%@%@%@",datestring,@" ",endtimestring];
event.startDate = [tempFormatter dateFromString:dateandtime];
event.endDate = [tempFormatter dateFromString:dateandtimeend];
[event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -60.0f * 24]];
[event addAlarm:[EKAlarm alarmWithRelativeOffset:60.0f * -15.0f]];
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
}
Run Code Online (Sandbox Code Playgroud)
从XML我得到这种格式的日期和时间:
日期字符串:28.10.2012
starttimestring:15:00
我想知道如何使用iOS中的EventKit从EventStore中获取所有事件.
这样我可以指定今天的所有事件:
- (NSArray *)fetchEventsForToday {
NSDate *startDate = [NSDate date];
// endDate is 1 day = 60*60*24 seconds = 86400 seconds from startDate
NSDate *endDate = [NSDate dateWithTimeIntervalSinceNow:86400];
// Create the predicate. Pass it the default calendar.
NSArray *calendarArray = [NSArray arrayWithObject:defaultCalendar];
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray];
// Fetch all events that match the predicate.
NSArray *events = [self.eventStore eventsMatchingPredicate:predicate];
return events;
}
Run Code Online (Sandbox Code Playgroud)
正确的应该使用NSPredicate,它是用以下创建的:
NSPredicate *predicate = [self.eventStore predicateForEventsWithStartDate:startDate endDate:endDate calendars:calendarArray];
Run Code Online (Sandbox Code Playgroud)
我试过用
distantPast
distantFuture
Run Code Online (Sandbox Code Playgroud)
作为startDate和endDate,没有好处.所以来自其他Q的其他A并不是我想要的.
谢谢!
编辑 …
我正在编写一个iPhone应用程序,它将使用EventKit框架在用户的日历中创建新事件.那部分工作得很好(除了它处理时区的不稳定方式 - 但这是另一个问题).我无法弄清楚的是如何获取用户日历的列表,以便他们可以选择将事件添加到哪个日历.我知道它是一个EKCalendar对象,但文档没有显示任何方式来获取整个集合.
提前致谢,
标记
我想知道是否有人知道如何使用APP的特定事件启动日历
我做了一些研究,我想出了两种方法,使用NSURL从应用程序内部打开本机日历
"calshow://" 在当前日期打开日历"calshow:\(someNSDate.timeIntervalSinceReferenceDate)" 打开日期为的日历 someNSDate我还发现这个网站列出calshow:x?eventid=id的网址,但我不知道,如果这个工程(列为不公开),我无法得到它的工作我自己使用,尝试:
event.calendarItemExternalIdentifier
event.eventIdentifier
event.calendarItemIdentifier
Run Code Online (Sandbox Code Playgroud)
目前我正在使用此代码在finalInterval日期,事件日期打开日历应用程序
if let day = hackathon?.start {
let today = NSDate()
let timeSince = NSDate.timeIntervalSinceReferenceDate() // this plus
let todayToFutureDate = day.timeIntervalSinceDate(today)
let finalInterval = todayToFutureDate + timeSince
UIApplication.sharedApplication().openURL(NSURL(string: "calshow:\(finalInterval)")!)
}
Run Code Online (Sandbox Code Playgroud)
我想要做的是打开日历,其中包含事件ID或类似事件的日历
如果您对更多信息有任何疑问,请问,我会在附近
通过iPhone的设置面板,您可以添加远程.ics日历格式的订阅.我有一个荷兰语iPhone应用程序,可以在应用程序中执行此操作(请参阅下面的屏幕截图,"abonneren op de agenda"表示"订阅日历"),但也必须有其他人.
我想模仿我的一个项目的这种行为,但我找不到这样做的API.看起来它不是EventKit的一部分,但是因为在示例应用程序中点击'subscribe'时没有应用程序切换,我怀疑它也不是url方案.
谁知道?

是否有可用于识别跨设备的日历的属性?
根据Apple文档,无法使用"calendarIdentifier"属性:
与日历完全同步将丢失此标识符.您应该有一个计划,通过缓存其他属性来处理标识符不再可读的日历.
我正在寻找类似于EKEvent.calendarItemExternalIdentifier的东西,它在设备上是相同且唯一的,但是对于日历.
阅读Apple的文档,我仍然对EKCalenderItem的calendarItemExternalIdentifier和EKEvent的eventIdentifier之间的差异感到困惑,我们应该使用哪一个来识别不同设备上的日历事件.特别:
EKCalendarItem calendarItemExternalIdentifier 日历服务器提供的日历项的外部标识符.(只读)
和
EKEvent eventIdentifier:事件的唯一标识符.(只读)
EKCalendarItem calendarItemExternalIdentifier是在iOS6中添加的,我原本认为这将是我需要保存的标识符,以便稍后调用,EKEventStore eventWithIdenfier:因为它声称:
此标识符允许您跨多个设备访问相同的事件或提醒.
但是在我自己的测试中,似乎当我创建并保存一个新的EKEvent时,我从EKEvent对象获得的eventIdenifier是唯一且有用的,而我得到的calendarItemExternalIdentifier似乎不适用于 EKEventStore eventWithIdenfier:
如果有人有确凿的答案,我很想知道.
我正在编写一个处理日历的应用程序.在应用程序中,我显示了用户启用或禁用的所有可用日历的列表.我没有将EventKitUI框架用于我自己的设计和UI.
通过轮询对象的calendars属性,我得到了一个整洁的日历列表EKEventStore.但是,在我的设备上,EKCalendar该列表中有一个对象未显示EKEventKitUI.这是调试器中对象的描述:
EKCalendar <0xcea6b60> {title = Agenda; type = Local; allowsModify = YES; color = #711A76;}
Run Code Online (Sandbox Code Playgroud)
我用荷兰语运行我的iPhone,这就是为什么标题是"日程"而不是"日历",但如果你用英语运行iPhone,那就是你会看到的.看起来这是iOS的默认日历,但由于我将所有日历设置为与iCloud同步,因此内置日历应用程序禁用它.我想在我自己的应用程序中禁用它,但我不知道如何.
从查看属性EKCalendar我无法辨别出我应该"隐藏"哪个日历.type这个默认日历的属性是"本地",但如果有人没有使用iCloud,我想所有的日历都是本地类型.subscription既不是,也不是allowsContentModifications.我已经看到人们根据它的标题隐藏默认日历的例子,但正如你所看到的,标题是本地化的,因此非常不切实际,只是感觉不对.
决定哪个日历是默认日历以及是否隐藏日历的诀窍是什么,以便与您的常规iCal /日历应用程序显示的日历列表并行?
编辑:虽然问题被标记为已回答,但答案中包含一个很大的"不,你不能".我通过添加设置面板开关来"隐藏本地日历"为我的用户解决了这个问题,但这是一个非常非常不优雅的解决方案.
我正在尝试使用iOS 9中的新主动助手功能来访问通过电子邮件自动创建的事件.这些事件显示在"在邮件中找到的事件"日历中.
要访问这些,我正在做以下事情
self.eventStore.requestAccessToEntityType(.Event, completion: { (granted, error) -> Void in
let predicate = eventStore.predicateForEventsWithStartDate(NSDate(timeIntervalSince1970: timestamp1), endDate: NSDate(timeIntervalSince1970: timestamp2), calendars: nil)
let events = eventStore.eventsMatchingPredicate(predicate)
}
Run Code Online (Sandbox Code Playgroud)
但是,未列出此日历中的事件.这是Apple的限制还是我可以通过其他任何方式访问它们?
我正在尝试创建日历,而不是日历事件而是日历.我无法获取本地来源,我的应用程序崩溃了.
这是我的代码:
let newCalendar = EKCalendar(for: .event, eventStore: eventStore)
newCalendar.title = "Some Calendar Name"
let sourcesInEventStore = eventStore.sources
newCalendar.source = sourcesInEventStore.filter{
(source: EKSource) -> Bool in
source.sourceType.rawValue == EKSourceType.local.rawValue
}.first!
Run Code Online (Sandbox Code Playgroud)
我完全关闭了我的iCloud,仍然无法获得本地资源.
我也试图让这个与iCloud打开工作,我想出了这个代码,但它不起作用
for let source in eventStore.sources
{
if(source.sourceType == EKSourceType.calDAV && source.title == "iCloud")
{
newCalendar.source = source
}
}
if(newCalendar.source == nil)
{
for let source2 in eventStore.sources
{
if(source2.sourceType == EKSourceType.local)
{
newCalendar.source = source2
}
}
}
Run Code Online (Sandbox Code Playgroud) eventkit ×10
ios ×6
calendar ×5
objective-c ×5
iphone ×4
ekevent ×3
swift ×3
cocoa-touch ×2
ekeventstore ×1
fetch ×1
list ×1
nsdate ×1
nsurl ×1
sdk ×1
swift3 ×1