Skip to content

Commit

Permalink
fix: gradle plugin 8 compatibility & new method for requesting calend…
Browse files Browse the repository at this point in the history
…ar permissions on iOS 17
  • Loading branch information
alperpacin committed Mar 1, 2024
1 parent ea9f746 commit 9174fc9
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ npm-debug.log
.DS_Store
android/build/*
xcuserdata
.idea
7 changes: 7 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ def safeExtGet(prop, fallback) {
}

android {

def agpVersion = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION
// Check AGP version for backward compatibility w/react-native versions still on gradle plugin 6
if (agpVersion.tokenize('.')[0].toInteger() >= 7) {
namespace "com.calendarevents"
}

compileSdkVersion safeExtGet('compileSdkVersion', 28)
buildToolsVersion safeExtGet('buildToolsVersion', '28.0.3')

Expand Down
27 changes: 19 additions & 8 deletions ios/RNCalendarEvents.m
Original file line number Diff line number Diff line change
Expand Up @@ -780,14 +780,25 @@ - (NSDictionary *)serializeCalendarEvent:(EKEvent *)event

RCT_EXPORT_METHOD(requestPermissions:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
{
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
NSString *status = granted ? @"authorized" : @"denied";
if (!error) {
resolve(status);
} else {
reject(@"error", @"authorization request error", error);
}
}];
if (@available(iOS 17.0, *)) {
[self.eventStore requestFullAccessToEventsWithCompletion:^(BOOL granted, NSError *error) {
NSString *status = granted ? @"authorized" : @"denied";
if (!error) {
resolve(status);
} else {
reject(@"error", @"authorization request error", error);
}
}];
} else {
[self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
NSString *status = granted ? @"authorized" : @"denied";
if (!error) {
resolve(status);
} else {
reject(@"error", @"authorization request error", error);
}
}];
}
}

RCT_EXPORT_METHOD(findCalendars:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject)
Expand Down

1 comment on commit 9174fc9

@alperpacin
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

android gradle plugin 8 compatibility: wmcmahan/pull/444
Uses new method for requesting calendar permissions on iOS 17: wmcmahan/pull/448

Please sign in to comment.