RNPermissionHandlerPhotoLibrary.m 1.2KB

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