如何在ios中以编程方式检索默认日历和提醒,我有一个简单的项目,只有一个按钮,我想点击按钮访问默认提醒和日历
我已经为此完成了简单的代码,但是它正常工作 以下是我的示例代码
#import "ViewController.h"
#import <EventKit/EventKit.h>
@interface ViewController ()
@end
@implementation ViewController
- (IBAction)btn:(id)sender {
EKEventStore *eventStore=[[EKEventStore alloc]init];
EKEvent *event =[EKEvent eventWithEventStore:eventStore];
NSDate *startDate=[[NSDate alloc]init];
NSDate *endDate =[[NSDate alloc]init];
event.title=@"Title for new event";
event.startDate=startDate;
event.endDate=endDate;
event.allDay=YES;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
// if (err == noErr){
// UIAlertView * alert = [[UIAlertView alloc]initWithTitle:@"Event create" message:@"how about that?" delegate:nil cancelButtonTitle:@"okey" otherButtonTitles:nil];
//
// [alert show];
}
当我在iphone 4s reale设备上运行时,它会显示以下错误:
2013-03-13 09:52:22.638 remind[774:907] defaultCalendarForNewEvents failed: Error Domain=EKCADErrorDomain Code=1013 "The operation couldn’t be completed. (EKCADErrorDomain error 1013.)"
答案 0 :(得分:1)
this is my .h header file where u have to declare this below code:
uikit framework
#import <UIKit/UIKit.h>
#import <EventKitUI/EventKitUI.h>
#define ALERT_Reminder 0
@interface GaSchedulesDeWorming : UIViewController<UITableViewDataSource, UITableViewDelegate, EKEventEditViewDelegate>
{
EKEventStore *eventStore;
}
this ins my implementation file .m:
**#import <EventKitUI/EventKitUI.h>**
add these package
以下代码用于打开默认日历以在iphone中设置提醒
EKEventStore *eventStore=[[EKEventStore alloc]init];
EKEvent *event =[EKEvent eventWithEventStore:eventStore];
NSDate *startDate=[[NSDate alloc]init];
NSDate *endDate =[[NSDate alloc]init];
event.title=@"Title for new event";
event.startDate=startDate;
event.endDate=endDate;
event.allDay=YES;
[event setCalendar:[eventStore defaultCalendarForNewEvents]];
NSError *err;
[eventStore saveEvent:event span:EKSpanThisEvent error:&err];
eventStore=[[EKEventStore alloc]init];
__block BOOL accessGranted = NO;
if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
accessGranted = granted;
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
} else {
accessGranted = YES;
}
if (accessGranted) {
}
EKEventEditViewController *controller = [[EKEventEditViewController alloc]init];
}