iphone - 将数据添加到日历不起作用

标签 iphone ios objective-c ios6 calendar

我正在尝试使用以下代码在日历中添加 session 详细信息。但是它不起作用。我总是收到错误代码(其他部分正在执行)。

EKEventStore *eventSotre = [[EKEventStore alloc] init];

EKEvent *event = [EKEvent eventWithEventStore:eventSotre];

event.title= @"Event Title";

NSDate *duedate = [[NSDate alloc] init];
event.startDate = duedate;
// also tried with below
// event.startDate = [[NSDate alloc] initWithTimeInterval:200 sinceDate:duedate];
event.endDate= [[NSDate alloc] initWithTimeInterval:600 sinceDate:duedate];

NSArray *arrAlarm = [NSArray arrayWithObject:[EKAlarm alarmWithAbsoluteDate:duedate]];
event.alarms= arrAlarm;

[event setCalendar:[eventSotre defaultCalendarForNewEvents]];
NSError *err;
BOOL isSuceess=[eventSotre saveEvent:event span:EKSpanThisEvent error:&err];

if(isSuceess){
    UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Event" message:@"Event added in calendar" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertview show];
    [alertview release];
}
else{
    UIAlertView *alertview = [[UIAlertView alloc] initWithTitle:@"Error" message:[err description] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertview show];
    [alertview release];
}
[eventSotre release];

知道我为什么要面对这个吗?我还有#import <EventKit/EventKit.h>在我的代码中,我也添加了相同的框架。

最佳答案

下面的链接解决了我的问题。

https://stackoverflow.com/a/13451544/1066828

问题是我有 iOS 6。

关于iphone - 将数据添加到日历不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16012819/

相关文章:

iphone - 如何正确释放 NSInitation 的保留参数?

ios - 无法在 ios9 上的 swift2 中获取航向数据(用于 compass 应用程序)

ios - 将 subview 添加到 self.tableView.tableHeaderView 不起作用

ios - TabView SwiftUI 中 TabItem 上的 LinearGradient

ios - SceneKit/ARKit 中的定位音频与 AudioKit

objective-c - 设计问题 : Core Animation, NSCollectionView 和 NSCollectionViewItems

javascript - 在 ios 上的 m.youtube.com 上导航的 uiwebview 上获得点击链接

iphone - 客户端在 iPhone 上禁用推送通知

iphone - 重复符号错误xcode iphone

ios - UINavCtrlr 推送动画将内容部分移开然后消失