1234567891011121314151617181920212223242526272829303132333435363738
  1. #import "RNPermissionHandlerMicrophone.h"
  2. @import AVFoundation;
  3. @implementation RNPermissionHandlerMicrophone
  4. + (NSArray<NSString *> * _Nonnull)usageDescriptionKeys {
  5. return @[@"NSMicrophoneUsageDescription"];
  6. }
  7. + (NSString * _Nonnull)handlerUniqueId {
  8. return @"ios.permission.MICROPHONE";
  9. }
  10. - (void)checkWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
  11. rejecter:(void (__unused ^ _Nonnull)(NSError * _Nonnull))reject {
  12. switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeAudio]) {
  13. case AVAuthorizationStatusNotDetermined:
  14. return resolve(RNPermissionStatusNotDetermined);
  15. case AVAuthorizationStatusRestricted:
  16. return resolve(RNPermissionStatusRestricted);
  17. case AVAuthorizationStatusDenied:
  18. return resolve(RNPermissionStatusDenied);
  19. case AVAuthorizationStatusAuthorized:
  20. return resolve(RNPermissionStatusAuthorized);
  21. }
  22. }
  23. - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
  24. rejecter:(void (^ _Nonnull)(NSError * _Nonnull))reject {
  25. [AVCaptureDevice requestAccessForMediaType:AVMediaTypeAudio
  26. completionHandler:^(__unused BOOL granted) {
  27. [self checkWithResolver:resolve rejecter:reject];
  28. }];
  29. }
  30. @end