RNPermissionHandlerCamera.m 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #import "RNPermissionHandlerCamera.h"
  2. @import AVFoundation;
  3. @implementation RNPermissionHandlerCamera
  4. + (NSArray<NSString *> * _Nonnull)usageDescriptionKeys {
  5. return @[@"NSCameraUsageDescription"];
  6. }
  7. + (NSString * _Nonnull)handlerUniqueId {
  8. return @"ios.permission.CAMERA";
  9. }
  10. - (void)checkWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
  11. rejecter:(void (__unused ^ _Nonnull)(NSError * _Nonnull))reject {
  12. switch ([AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo]) {
  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:AVMediaTypeVideo
  26. completionHandler:^(__unused BOOL granted) {
  27. [self checkWithResolver:resolve rejecter:reject];
  28. }];
  29. }
  30. @end