RNPPhoto.m 1008B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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 <AssetsLibrary/AssetsLibrary.h>
  10. @import Photos;
  11. @implementation RNPPhoto
  12. + (NSString *)getStatus
  13. {
  14. int status = [PHPhotoLibrary authorizationStatus];
  15. switch (status) {
  16. case PHAuthorizationStatusAuthorized:
  17. return RNPStatusAuthorized;
  18. case PHAuthorizationStatusDenied:
  19. return RNPStatusDenied;
  20. case PHAuthorizationStatusRestricted:
  21. return RNPStatusRestricted;
  22. default:
  23. return RNPStatusUndetermined;
  24. }
  25. }
  26. + (void)request:(void (^)(NSString *))completionHandler
  27. {
  28. void (^handler)(void) = ^(void) {
  29. dispatch_async(dispatch_get_main_queue(), ^{
  30. completionHandler([self.class getStatus]);
  31. });
  32. };
  33. [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  34. handler();
  35. }];
  36. }
  37. @end