RNPMediaLibrary.m 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. #if TARGET_OS_SIMULATOR
  14. return RNPStatusRestricted;
  15. #else
  16. if (@available(iOS 9.3, *)) {
  17. switch ([MPMediaLibrary authorizationStatus]) {
  18. case MPMediaLibraryAuthorizationStatusAuthorized:
  19. return RNPStatusAuthorized;
  20. case MPMediaLibraryAuthorizationStatusDenied:
  21. return RNPStatusDenied;
  22. case MPMediaLibraryAuthorizationStatusRestricted:
  23. return RNPStatusRestricted;
  24. default:
  25. return RNPStatusUndetermined;
  26. }
  27. } else {
  28. return RNPStatusAuthorized;
  29. }
  30. #endif
  31. }
  32. + (void)request:(void (^)(NSString *))completionHandler
  33. {
  34. #if TARGET_OS_SIMULATOR
  35. completionHandler(RNPStatusRestricted);
  36. #else
  37. if (@available(iOS 9.3, *)) {
  38. void (^handler)(void) = ^(void) {
  39. dispatch_async(dispatch_get_main_queue(), ^{
  40. completionHandler([self.class getStatus]);
  41. });
  42. };
  43. [MPMediaLibrary requestAuthorization:^(MPMediaLibraryAuthorizationStatus status){
  44. handler();
  45. }];
  46. } else {
  47. completionHandler(RNPStatusAuthorized);
  48. }
  49. #endif
  50. }
  51. @end