12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. //
  2. // RNPCamera.m
  3. // ReactNativePermissions
  4. //
  5. // Created by Yonah Forst on 11/07/16.
  6. // Copyright © 2016 Yonah Forst. All rights reserved.
  7. //
  8. #import "RNPAudioVideo.h"
  9. #import <AVFoundation/AVFoundation.h>
  10. @implementation RNPAudioVideo
  11. + (NSString *)getStatus:(NSString *)type
  12. {
  13. int status = [AVCaptureDevice authorizationStatusForMediaType:[self typeFromString:type]];
  14. switch (status) {
  15. case AVAuthorizationStatusAuthorized:
  16. return RNPStatusAuthorized;
  17. case AVAuthorizationStatusDenied:
  18. return RNPStatusDenied;
  19. case AVAuthorizationStatusRestricted:
  20. return RNPStatusRestricted;
  21. default:
  22. return RNPStatusUndetermined;
  23. }
  24. }
  25. + (void)request:(NSString *)type completionHandler:(void (^)(NSString *))completionHandler
  26. {
  27. [AVCaptureDevice requestAccessForMediaType:[self typeFromString:type]
  28. completionHandler:^(BOOL granted) {
  29. dispatch_async(dispatch_get_main_queue(), ^{
  30. completionHandler([RNPAudioVideo getStatus:type]);
  31. });
  32. }];
  33. }
  34. + (NSString *)typeFromString:(NSString *)string {
  35. if ([string isEqualToString:@"audio"]) {
  36. return AVMediaTypeAudio;
  37. } else {
  38. return AVMediaTypeVideo;
  39. }
  40. }
  41. @end