RNPSpeechRecognition.m 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //
  2. // RNPSpeechRecognition.m
  3. // ReactNativePermissions
  4. //
  5. // Created by Tres Trantham on 1/11/17.
  6. // Copyright © 2017 Yonah Forst. All rights reserved.
  7. //
  8. #import "RNPSpeechRecognition.h"
  9. #import <Speech/Speech.h>
  10. @implementation RNPSpeechRecognition
  11. + (NSString *)getStatus
  12. {
  13. int status = [SFSpeechRecognizer authorizationStatus];
  14. switch (status) {
  15. case SFSpeechRecognizerAuthorizationStatusAuthorized:
  16. return RNPStatusAuthorized;
  17. case SFSpeechRecognizerAuthorizationStatusDenied:
  18. return RNPStatusDenied;
  19. case SFSpeechRecognizerAuthorizationStatusRestricted:
  20. return RNPStatusRestricted;
  21. default:
  22. return RNPStatusUndetermined;
  23. }
  24. }
  25. + (void)request:(void (^)(NSString *))completionHandler
  26. {
  27. void (^handler)(void) = ^(void) {
  28. dispatch_async(dispatch_get_main_queue(), ^{
  29. completionHandler([self.class getStatus]);
  30. });
  31. };
  32. [SFSpeechRecognizer requestAuthorization:^(SFSpeechRecognizerAuthorizationStatus status) {
  33. handler();
  34. }];
  35. }
  36. @end