From 9174fc94f8ed288a5e831b53eeb4e92f619a3c71 Mon Sep 17 00:00:00 2001 From: Alper Pacin Date: Fri, 1 Mar 2024 10:33:03 +0300 Subject: [PATCH] fix: gradle plugin 8 compatibility & new method for requesting calendar permissions on iOS 17 --- .gitignore | 1 + android/build.gradle | 7 +++++++ ios/RNCalendarEvents.m | 27 +++++++++++++++++++-------- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 769f3f9..9b0c785 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ npm-debug.log .DS_Store android/build/* xcuserdata +.idea \ No newline at end of file diff --git a/android/build.gradle b/android/build.gradle index 6782479..0238b0c 100644 --- a/android/build.gradle +++ b/android/build.gradle @@ -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') diff --git a/ios/RNCalendarEvents.m b/ios/RNCalendarEvents.m index 4b67ddb..93848b5 100644 --- a/ios/RNCalendarEvents.m +++ b/ios/RNCalendarEvents.m @@ -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)