RNPermissionHandlerSpeechRecognition.m 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #import "RNPermissionHandlerSpeechRecognition.h"
  2. @import Speech;
  3. @implementation RNPermissionHandlerSpeechRecognition
  4. + (NSArray<NSString *> * _Nonnull)usageDescriptionKeys {
  5. return @[@"NSSpeechRecognitionUsageDescription"];
  6. }
  7. + (NSString * _Nonnull)handlerUniqueId {
  8. return @"ios.permission.SPEECH_RECOGNITION";
  9. }
  10. - (void)checkWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
  11. rejecter:(void (__unused ^ _Nonnull)(NSError * _Nonnull))reject {
  12. if (@available(iOS 10.0, *)) {
  13. switch ([SFSpeechRecognizer authorizationStatus]) {
  14. case SFSpeechRecognizerAuthorizationStatusNotDetermined:
  15. return resolve(RNPermissionStatusNotDetermined);
  16. case SFSpeechRecognizerAuthorizationStatusRestricted:
  17. return resolve(RNPermissionStatusRestricted);
  18. case SFSpeechRecognizerAuthorizationStatusDenied:
  19. return resolve(RNPermissionStatusDenied);
  20. case SFSpeechRecognizerAuthorizationStatusAuthorized:
  21. return resolve(RNPermissionStatusAuthorized);
  22. }
  23. } else {
  24. resolve(RNPermissionStatusNotAvailable);
  25. }
  26. }
  27. - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
  28. rejecter:(void (^ _Nonnull)(NSError * _Nonnull))reject {
  29. if (@available(iOS 10.0, *)) {
  30. [SFSpeechRecognizer requestAuthorization:^(__unused SFSpeechRecognizerAuthorizationStatus status) {
  31. [self checkWithResolver:resolve rejecter:reject];
  32. }];
  33. } else {
  34. resolve(RNPermissionStatusNotAvailable);
  35. }
  36. }
  37. @end