1

This bit of code is intended to print my default calendar in iCal on my Mac but instead returns (null). Do I need to change something in the code or settings to be able to access my calendars? I'm running this in Xcode 4.5.2.

#import <Foundation/Foundation.h>
#import <EventKit/EventKit.h>


int main(int argc, const char * argv[])
{

    EKEventStore *store = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityMaskEvent];
    NSLog(@"%@",[store defaultCalendarForNewEvents].calendarIdentifier);
    return 0;
}
ripperbone
  • 31
  • 3
  • Related: [Problems accessing Calendar using EKEventStore on OSX Sierra with Swift 3](https://stackoverflow.com/q/40298000/4975230) – jrh Jan 24 '21 at 01:44

1 Answers1

1

For me the above code returns the identifier of the default calendar correctly (on 10.8.2).

Is your application sandboxed? The result will be (null) if you don't allow calendar access while sandboxed:

enter image description here

I'm not sure if this is possible at all, but also check if there is a default calendar selected. (I have one selected, and could not set the selection to none in Calendar.app).

Joris Kluivers
  • 11,894
  • 2
  • 48
  • 47
  • 1
    Thanks for your suggestion. I'm on 10.7.5 and I think that this might be the problem but I'm not sure where you found the checkbox to allow Calendar Data Access. Is this a setting in Xcode somewhere? – ripperbone Jan 22 '13 at 19:11
  • Yes, its the `com.apple.security.personal-information.calendars` setting in your sandbox entitlements file. You can configure sandboxing by going to the Summary tab of your target configuration. The [App Sandbox Design Guide: Quick start](http://developer.apple.com/library/mac/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxQuickStart/AppSandboxQuickStart.html#//apple_ref/doc/uid/TP40011183-CH2-SW3) might be of help. – Joris Kluivers Jan 22 '13 at 19:49
  • I found the options for sandboxing when I created a new Cocoa Application (I had been choosing Command Line Tool). I made sure that sandbox mode was unchecked but still no luck. I don't think code signing should be required to access the calendar data, right? I get no errors in Xcode but I did find an interesting message in Console: 1/23/13 12:33:50.309 AM getEvents: (null) 1/23/13 12:33:50.312 AM com.apple.debugserver-194: 2 +0.172950 sec [11f5/1a03]: error: ::read ( 1, 0x10a3c9a60, 1024 ) => -1 err = Bad file descriptor (0x00000009) – ripperbone Jan 23 '13 at 06:37
  • For me it only seemed to work when sandboxed. I didn't find any documentation about `EKEventStore` and sandboxing, so I'm not sure if this behaviour is intended or a bug. – Joris Kluivers Jan 23 '13 at 07:33