RNPPhoto.m 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // RNPPhoto.m
  3. // ReactNativePermissions
  4. //
  5. // Created by Yonah Forst on 11/07/16.
  6. // Copyright © 2016 Yonah Forst. All rights reserved.
  7. //
  8. #import "RNPPhoto.h"
  9. #import <AddressBook/AddressBook.h>
  10. #import <AssetsLibrary/AssetsLibrary.h>
  11. @import Photos;
  12. @implementation RNPPhoto
  13. + (NSString *)getStatus
  14. {
  15. int status = [PHPhotoLibrary authorizationStatus];
  16. switch (status) {
  17. case PHAuthorizationStatusAuthorized:
  18. return RNPStatusAuthorized;
  19. case PHAuthorizationStatusDenied:
  20. return RNPStatusDenied;
  21. case PHAuthorizationStatusRestricted:
  22. return RNPStatusRestricted;
  23. default:
  24. return RNPStatusUndetermined;
  25. }
  26. }
  27. + (void)request:(void (^)(NSString *))completionHandler
  28. {
  29. void (^handler)(void) = ^(void) {
  30. dispatch_async(dispatch_get_main_queue(), ^{
  31. completionHandler([self.class getStatus]);
  32. });
  33. };
  34. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  35. handler();
  36. }];
  37. }
  38. @end