Question

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--------------
Was it helpful?

Solution

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?

OTHER TIPS

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 ];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top