1

I've written this code below just to get it to compile but this will not work, because I need to have a deployment target of 10.8.

what is going on is I need access to EKEventStore , so when someone downloads this app, it runs fine in 10.8, but someone downloading in 10.9 would get errors, because the app doesn't have Privacy permission to the calendar. Since it is being compiled for 10.8, it has no access to the method requestAccessToEntityType:EKEntityTypeEvent..

how would one go about doing this?

on a related note, how do you compile code for 10.9, other code for 10.8, and call those different parts depending on the environment it is in? remembering this is for the Mac App Store, and if that is the way to go, be illustrative, as if you are talking to someone who has no idea how to begin to do this, because I don't.. thanks.

    //------------------check authorization of calendars--------------
#if (__MAC_OS_X_VERSION_MIN_REQUIRED >= 1090) || (__IPHONE_OS_VERSION_MIN_REQUIRED)
    if(!eventStore) eventStore = [[EKEventStore alloc] init];
    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)  //.............put this back in...
     {
         if (granted)
         {   
NSLog(@"granted permission to eventstore!");
            authorizedEventStore = YES;
            authorizedCalendar();
         }
         else
         {
NSLog(@"Not granted");
            authorizedEventStore = NO;
            notAuthorized();
         }
     }];
#else
NSLog(@"not able to request");
    if(!eventStore) eventStore = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityMaskEvent];
    authorizedEventStore = YES;
    authorizedCalendar();
#endif
    //------------------end check authorization of calendars--------------
hokkuk
  • 675
  • 5
  • 21

2 Answers2

2

To request access on OS X use:

EKEventStore *eventStore = nil;
if ([EKEventStore respondsToSelector:@selector(authorizationStatusForEntityType:)]) {
    // 10.9 style
    eventStore = [[EKEventStore alloc] init];
    [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
    {
        // your completion
    }];
} else {
    // 10.8 style
    eventStore = [[EKEventStore alloc] initWithAccessToEntityTypes:EKEntityMaskEvent ];
}
mahal tertin
  • 3,239
  • 24
  • 41
  • this is what I effectively have now... and it is on the Mac app store, however in a 10.9 environment, this call is not raising the "request access"... so the app just produces errors. So this can't be used in both 10.8 and 10.9; I believe your answer below is the correct way. If I assume it properly handles the ---if responds statement... which i will find out when it is updated in the app store. I actually had this set up like that, but mistakenly believed since i was switching back and forth to 10.8 and 10.9 baseSDK that it would produce an error on 10.8 I see what is going on now. – hokkuk Oct 28 '13 at 15:51
  • so I am glad i asked effectively two questions, because this would have not given me the push in the correct direction, the answer below cleared my fog. thanks. – hokkuk Oct 28 '13 at 15:54
  • I just updated the code to show you an example how you'd check for respondsToSelector. Hope it helps. – mahal tertin Oct 29 '13 at 10:18
  • It's way after, not sure you'll see it, but thanks for this! Just saved my ass. – CBanga Jun 21 '14 at 05:08
2

To have an App that runs on several OS versions:

  • Set your Base SDK to the latest version of the OS you support, in your case 10.9
  • Set the Deployment Target to the earliest OS you want your code to launch on
  • For all calls that don't exist in earlier versions of the OS, you must test before you call, either by using respondsToSelector: (for methods) or testing against nil (for functions and statics). You can if you like do a check for the OS version, but it's more robust to check the specific call.

see also: How to conditionally use a new Cocoa API and How do I include calls to methods only present in one operating system version when compiling for multiple versions?

Community
  • 1
  • 1
mahal tertin
  • 3,239
  • 24
  • 41
  • hmmm, i had that in before, and when i switched back and forth to the baseSDK of 10.8, it wouldn't compile and shows error. no visible interface for EKEventStore declares selector etc... I had apparently wrongly assumed that if i used baseSDK of 10.9, and the app running in 10.8, it would also see a similar crash or error. But I see what is going on now, thanks. – hokkuk Oct 28 '13 at 15:40