Skip to content

Commit

Permalink
feat: Add Support for iOS 17 (#11)
Browse files Browse the repository at this point in the history
Considering the changes introduced in EventKit for iOS 17, add the "requestFullAccessToEventWithCompletion:" method to trigger the alert to allow full access to the Calendar. This allows the plugin to keep a similar behaviour to the 16 version (and previous). Considering that the methods use the same access grant closure, this was moved into a local variable that can be called by all callers.
The iOS 5 condition was removed as our current supported minimum version is higher than that one.
Add the "NSCalendarsFullAccessUsageDescription" info.plist key added by Apple for iOS 17. It uses the same text set for "NSCalendarsUsageDescription", keeping the same experience as before.
Remove the SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO macro as it's not used in the code.

References: https://outsystemsrd.atlassian.net/browse/RMET-2726
  • Loading branch information
OS-ricardomoreirasilva authored Aug 25, 2023
1 parent 9a29b8b commit e192174
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
4 changes: 4 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
<config-file target="*-Info.plist" parent="NSCalendarsUsageDescription">
<string>$CALENDAR_USAGE_DESCRIPTION</string>
</config-file>
<!-- Usage description for Full Access of the Calendar, available since iOS 17 -->
<config-file target="*-Info.plist" parent="NSCalendarsFullAccessUsageDescription">
<string>$CALENDAR_USAGE_DESCRIPTION</string>
</config-file>
<!-- Usage description of the Contacts for iOS 6+, mandatory since iOS 10 -->
<preference name="CONTACTS_USAGE_DESCRIPTION" default=" " />
<config-file target="*-Info.plist" parent="NSContactsUsageDescription">
Expand Down
41 changes: 24 additions & 17 deletions src/ios/Calendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#import <EventKitUI/EventKitUI.h>
#import <EventKit/EventKit.h>

#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)

@implementation Calendar
@synthesize eventStore;
@synthesize interactiveCallbackId;
Expand All @@ -16,22 +14,31 @@ - (void) pluginInitialize {
}

- (void) initEventStoreWithCalendarCapabilities {
__block BOOL accessGranted = NO;
EKEventStore* eventStoreCandidate = [[EKEventStore alloc] init];
if([eventStoreCandidate respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
__block BOOL accessGranted = NO;
EKEventStore* eventStoreCandidate = [[EKEventStore alloc] init];
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[eventStoreCandidate requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
accessGranted = granted;
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
} else { // we're on iOS 5 or older
accessGranted = YES;
}

if (accessGranted) {
self.eventStore = eventStoreCandidate;
}
void (^eventStoreCandidateCompletion)(BOOL, NSError *) = ^void(BOOL granted, NSError *error) {
accessGranted = granted;
dispatch_semaphore_signal(sema);
};

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000
if (@available(iOS 17.0, *)) {
if ([eventStoreCandidate respondsToSelector:@selector(requestFullAccessToEventsWithCompletion:)]) {
[eventStoreCandidate requestFullAccessToEventsWithCompletion:eventStoreCandidateCompletion];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}
} else
#endif
if ([eventStoreCandidate respondsToSelector:@selector(requestAccessToEntityType:completion:)]) {
[eventStoreCandidate requestAccessToEntityType:EKEntityTypeEvent completion:eventStoreCandidateCompletion];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
}

if (accessGranted) {
self.eventStore = eventStoreCandidate;
}
}

#pragma mark Helper Functions
Expand Down

0 comments on commit e192174

Please sign in to comment.