RNPMediaLibrary.m 1023B

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