12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // RNPEvent.m
  3. // ReactNativePermissions
  4. //
  5. // Created by Yonah Forst on 11/07/16.
  6. // Copyright © 2016 Yonah Forst. All rights reserved.
  7. //
  8. #import "RNPEvent.h"
  9. #import <EventKit/EventKit.h>
  10. @implementation RNPEvent
  11. + (NSString *)getStatus:(NSString *)type
  12. {
  13. int status = [EKEventStore authorizationStatusForEntityType:[self typeFromString:type]];
  14. switch (status) {
  15. case EKAuthorizationStatusAuthorized:
  16. return RNPStatusAuthorized;
  17. case EKAuthorizationStatusDenied:
  18. return RNPStatusDenied;
  19. case EKAuthorizationStatusRestricted:
  20. return RNPStatusRestricted;
  21. default:
  22. return RNPStatusUndetermined;
  23. }
  24. }
  25. + (void)request:(NSString *)type completionHandler:(void (^)(NSString *))completionHandler
  26. {
  27. EKEventStore *aStore = [[EKEventStore alloc] init];
  28. [aStore requestAccessToEntityType:[self typeFromString:type] completion:^(BOOL granted, NSError *error) {
  29. dispatch_async(dispatch_get_main_queue(), ^{
  30. completionHandler([self getStatus:type]);
  31. });
  32. }];
  33. }
  34. +(EKEntityType)typeFromString:(NSString *)string {
  35. if ([string isEqualToString:@"reminder"]) {
  36. return EKEntityTypeReminder;
  37. } else {
  38. return EKEntityTypeEvent;
  39. }
  40. }
  41. @end