RNPermissionHandlerPhotoLibrary.m 1.1KB

12345678910111213141516171819202122232425262728293031323334
  1. #import "RNPermissionHandlerPhotoLibrary.h"
  2. @import Photos;
  3. @implementation RNPermissionHandlerPhotoLibrary
  4. + (NSArray<NSString *> *)usageDescriptionKeys {
  5. return @[@"NSPhotoLibraryUsageDescription"];
  6. }
  7. - (void)checkWithResolver:(void (^)(RNPermissionStatus status))resolve
  8. withRejecter:(void (__unused ^)(NSError *error))reject {
  9. switch ([PHPhotoLibrary authorizationStatus]) {
  10. case PHAuthorizationStatusNotDetermined:
  11. return resolve(RNPermissionStatusNotDetermined);
  12. case PHAuthorizationStatusRestricted:
  13. return resolve(RNPermissionStatusRestricted);
  14. case PHAuthorizationStatusDenied:
  15. return resolve(RNPermissionStatusDenied);
  16. case PHAuthorizationStatusAuthorized:
  17. return resolve(RNPermissionStatusAuthorized);
  18. }
  19. }
  20. - (void)requestWithOptions:(__unused NSDictionary * _Nullable)options
  21. withResolver:(void (^)(RNPermissionStatus status))resolve
  22. withRejecter:(void (^)(NSError *error))reject {
  23. [PHPhotoLibrary requestAuthorization:^(__unused PHAuthorizationStatus status) {
  24. [self checkWithResolver:resolve withRejecter:reject];
  25. }];
  26. }
  27. @end