我正在尝试从我的应用程序将事件保存到日历中。我的代码适用于iOS 7,但在iOS 6上,它返回未设置日历。
在iOS 7上,该应用程序会提示用户授予对日历的访问权限,但对于iOS 6则不会出现这样的提示。尽管在设置->隐私->日历中已向该应用程序授予访问权限。
是的,我已经实现了requestAccessToEntityType:completion:
。
这是我的代码段。
EKEventStore *objStore = [[EKEventStore alloc]init];
if ([objStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
// iOS 6 and later
[objStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
if (granted)
{
// code here for when the user allows your app to access the calendar
EKEvent *calEvent = [EKEvent eventWithEventStore:objStore];
calEvent.title = mstrTitleEvent;
calEvent.startDate = self.dateToBeSet;
calEvent.endDate = self.dateToBeSet;
calEvent.calendar = objStore.defaultCalendarForNewEvents;
EKAlarm *objAlarm = [EKAlarm alarmWithAbsoluteDate:self.dateToBeSet];
[calEvent …
Run Code Online (Sandbox Code Playgroud)