RNPermissionHandlerReminders.m 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #import "RNPermissionHandlerReminders.h"
  2. @import EventKit;
  3. @implementation RNPermissionHandlerReminders
  4. + (NSArray<NSString *> * _Nonnull)usageDescriptionKeys {
  5. return @[@"NSRemindersUsageDescription"];
  6. }
  7. + (NSString * _Nonnull)handlerUniqueId {
  8. return @"ios.permission.REMINDERS";
  9. }
  10. - (void)checkWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
  11. rejecter:(void (__unused ^ _Nonnull)(NSError * _Nonnull))reject {
  12. switch ([EKEventStore authorizationStatusForEntityType:EKEntityTypeReminder]) {
  13. case EKAuthorizationStatusNotDetermined:
  14. return resolve(RNPermissionStatusNotDetermined);
  15. case EKAuthorizationStatusRestricted:
  16. return resolve(RNPermissionStatusRestricted);
  17. case EKAuthorizationStatusDenied:
  18. return resolve(RNPermissionStatusDenied);
  19. case EKAuthorizationStatusAuthorized:
  20. return resolve(RNPermissionStatusAuthorized);
  21. }
  22. }
  23. - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
  24. rejecter:(void (^ _Nonnull)(NSError * _Nonnull))reject {
  25. [[EKEventStore new] requestAccessToEntityType:EKEntityTypeReminder
  26. completion:^(__unused BOOL granted, NSError * _Nullable error) {
  27. if (error != nil) {
  28. reject(error);
  29. } else {
  30. [self checkWithResolver:resolve rejecter:reject];
  31. }
  32. }];
  33. }
  34. @end