这是我的代码:
NSString * calID = [[NSUserDefaults standardUserDefaults] objectForKey:@"calendarIdentifier"];
EKCalendar *cal = [eventStore calendarWithIdentifier:calID];
// If calendar exists
if(cal)
{
// Retrieve all existing events until today
NSPredicate *predicate = [eventStore predicateForEventsWithStartDate:[NSDate distantPast] endDate:[NSDate date] calendars:@[cal]];
self.events = [eventStore eventsMatchingPredicate:predicate];
if(self.events==nil)
NSLog(@"nil events!");
}
Run Code Online (Sandbox Code Playgroud)
calendarItentifier是我在程序中创建日历时存储的变量,因此不是我在错误的日历上添加事件的情况.
但是,代码无法检索日历上的过去事件,它只返回nil到self.events.但我DID在日历上添加事件.有什么能告诉我代码是否有问题?
背景:
我现在可以看到如何自定义EKEventView的颜色,这是一个苹果视图,可用于显示日历事件.代码是我的帖子:这个代码将来证明自定义EKEventViews的颜色(代码附加)
如果这个视图是EDIT'able,那么苹果EKEventView类然后显示模态"EKEventEditView"视图.
问题:
与API的链接:
EKEventViewController:http://developer.apple.com/library/ios/#documentation/EventKitUI/Reference/EKEventViewControllerClassRef/Reference/Reference.html
EKEventEditViewController - http://developer.apple.com/library/ios/#documentation/EventKitUI/Reference/EKEventEditViewControllerClassRef/Reference/Reference.html
我遇到了问题.我需要知道我的EventStore中的事件何时被更改,所以对于这种情况我使用EKEventStoreChangedNotification但是这个通知返回给我难以理解的字典,userInfo
它看起来像这样:
EKEventStoreChangedObjectIDsUserInfoKey = ("x-apple-eventkit:///Event/p429" );
Run Code Online (Sandbox Code Playgroud)
我不知道如何使用此数据来访问已更改的对象.请帮我
我有应用程序,我必须在默认日历中添加事件,直到iOS 10正常.现在在iOS 10中它不授予访问权限.我已经开始use legacy swift language version了yes.我的代码是
let eventStore = EKEventStore()
switch EKEventStore.authorizationStatusForEntityType(EKEntityType.Event) {
case .Authorized:
//access
case .Denied:
print("Access denied")
case .NotDetermined:
eventStore.requestAccessToEntityType(EKEntityType.Event, completion:
{[weak self] (granted: Bool, error: NSError?) -> Void in
if granted {
//access
} else {
print("Access denied")
}
})
default:
print("Case Default")
}
Run Code Online (Sandbox Code Playgroud)
调试我的应用程序eventStore.requestAccessToEntityType在Xcode 8中崩溃.
我的应用程序是实时的,我需要解决它.任何帮助都是适当的.提前致谢.
首次获取数据时,EventKit显示错误。
[EventKit]获取所有日历时出错:域= EKCADErrorDomain代码= 1019错误(“空)” 2018-01-17 19:19:22.190518 + 0530 StickyNoteApp [426:40382] [EventKit]为新事件获取默认日历时出错:错误Domain = EKCADErrorDomain代码= 1019“(空)” 2018-01-17 19:19:22.190556 + 0530 StickyNoteApp [426:40382] [EventKit]未提供对象ID。不会发现对象是否存在。视图将出现
[EventKit] CADDatabaseFetchCalendarItemsWithPredicate尝试的响应块中的错误(1019)1/3 2018-01-17 19:24:54.942170 + 0530 StickyNoteApp [426:40382] CADDatabaseFetchCalendarItemsWithPredicate尝试的响应块中的错误(1019) 2018-01-17 19:24:54.942572 + 0530 StickyNoteApp [426:40382] [EventKit] CADDatabaseFetchCalendarItemsWithPredicate尝试的答复块中出现错误(1019)3/3 2018-01-17 19:24:54.942588 + 0530 StickyNoteApp [426: 40382] [EventKit] CADDatabaseFetchCalendarItemsWithPredicate的所有重试已用尽2018-01-17 19:19:22.242094 + 0530
我正在尝试从日历中获取事件,而我正在使用此方法执行此操作:
predicateForEventsWithStartDate:endDate:calendars:
Run Code Online (Sandbox Code Playgroud)
但如果我创建这样的开始日期:
NSString *str =@"3/15/1980 9:15 PM";
NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"MM/dd/yyyy hh:mm a"];
NSTimeZone *gmt = [NSTimeZone timeZoneWithAbbreviation:@"GMT"];
[formatter setTimeZone:gmt];
NSDate *date = [formatter dateFromString:str];
Run Code Online (Sandbox Code Playgroud)
然后我这样做:
predicate = [eventStore predicateForEventsWithStartDate:date endDate:endDate calendars: [eventStore calendarsForEntityType:EKEntityTypeEvent]];
NSArray *eventArray = [eventStore eventsMatchingPredicate:predicate];
Run Code Online (Sandbox Code Playgroud)
eventArray是零,相反,如果我使用:
[NSDate date]
Run Code Online (Sandbox Code Playgroud)
找到我从今天到未来的事件,而不是旧日期不起作用,我也试过其他旧日期,但阵列总是零...
如果今天是5月6日星期二下午2点
event.startDate = [[NSDate alloc] init];
event.allDay = YES;
[dateFormat setDateFormat:EEEE, MMMM dd, yyyy];
NSString* dayStr = [dateFormat stringFromDate:event.startDate];
timeDetails.text = [NSString stringWithFormat:@"%@\nAll day", dayStr];
Run Code Online (Sandbox Code Playgroud)
结果于5月5日星期一
没有allDay设置的相同代码
event.startDate = [[NSDate alloc] init];
[dateFormat setDateFormat:EEEE, MMMM dd, yyyy];
NSString* dayStr = [dateFormat stringFromDate:event.startDate];
timeDetails.text = [NSString stringWithFormat:@"%@\nAll day", dayStr];
Run Code Online (Sandbox Code Playgroud)
结果在5月6日星期二这是正确的.有人有任何线索吗?
该EKCalendarItem有属性"位置",但它是一个NSString.新的iOS8功能显示了一个很好的事件地图,所以必须CLLocationCoordinate2D附加一个EKCalendarItem,正确的?我在哪里可以找到这个CLLocationCoordinate2D?
一种解决方案可能是:
创建一个新模型EKEventExt并在它们之间添加一对一关系,我不确定它是否可行,因为EKEventExt它存储在我的一个sqlite中,EKEvent并且存储在事件存储中。
在 EKEvent 中,一旦我没有为事件设置任何警报,我就会在日历应用程序中查看它,它会在 5 分钟前向我显示警报。为什么 ?我不明白。
我的要求
我想在给定特定时间之前设置两个警报,1 个警报,例如“5 分钟、15 分钟、30 分钟、1 小时”。需要在事件时间设置2秒警报。
在搜索如何在事件中添加警报的基础上,我为添加事件做了一些事情,但它不起作用。很多尝试但在日历中没有效果。
请参阅下面的代码,我根据我的要求尝试了两种方式,我使用开关盒,甚至尝试添加单个警报。两者都不起作用。
我该怎么办?
提出任何建议、解决方案、想法
谢谢
let event:EKEvent = EKEvent(eventStore: appleEventStore)
event.title = tempDescription
event.startDate = startDate as Date
event.endDate = endDate as Date
event.isAllDay = false
event.notes = "This is a note"
event.calendar = cal
do {
try appleEventStore.save(event, span: .thisEvent)
print("events added with dates:")
let alarm = EKAlarm(relativeOffset: 600)
event.addAlarm(alarm)
switch tempalertid {
case "1":
let aInterval: TimeInterval = -5 * 60 …Run Code Online (Sandbox Code Playgroud) ekevent ×10
ios ×8
ekeventstore ×4
ekeventkit ×3
calendar ×2
iphone ×2
swift ×2
alarm ×1
cocoa-touch ×1
eventkit ×1
icalendar ×1
ios8 ×1
location ×1
objective-c ×1
weekday ×1