RNPMediaLibrary.m 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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 "RNPMediaLibrary.h"
  9. #import <MediaPlayer/MediaPlayer.h>
  10. @implementation RNPMediaLibrary
  11. + (NSString *)getStatus
  12. {
  13. int status = [MPMediaLibrary authorizationStatus];
  14. switch (status) {
  15. case MPMediaLibraryAuthorizationStatusAuthorized:
  16. return RNPStatusAuthorized;
  17. case MPMediaLibraryAuthorizationStatusDenied:
  18. return RNPStatusDenied;
  19. case MPMediaLibraryAuthorizationStatusRestricted:
  20. return RNPStatusRestricted;
  21. default:
  22. return RNPStatusUndetermined;
  23. }
  24. }
  25. + (void)request:(void (^)(NSString *))completionHandler
  26. {
  27. void (^handler)(void) = ^(void) {
  28. dispatch_async(dispatch_get_main_queue(), ^{
  29. completionHandler([self.class getStatus]);
  30. });
  31. };
  32. [MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status){
  33. handler();
  34. }];
  35. }
  36. @end