RNPermissionHandlerSiri.m 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #import "RNPermissionHandlerSiri.h"
  2. @import Intents;
  3. @implementation RNPermissionHandlerSiri
  4. + (NSArray<NSString *> * _Nonnull)usageDescriptionKeys {
  5. return @[@"NSSiriUsageDescription"];
  6. }
  7. + (NSString * _Nonnull)handlerUniqueId {
  8. return @"ios.permission.SIRI";
  9. }
  10. - (void)checkWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
  11. rejecter:(void (__unused ^ _Nonnull)(NSError * _Nonnull))reject {
  12. if (@available(iOS 10.0, *)) {
  13. switch ([INPreferences siriAuthorizationStatus]) {
  14. case INSiriAuthorizationStatusNotDetermined:
  15. return resolve(RNPermissionStatusNotDetermined);
  16. case INSiriAuthorizationStatusRestricted:
  17. return resolve(RNPermissionStatusRestricted);
  18. case INSiriAuthorizationStatusDenied:
  19. return resolve(RNPermissionStatusDenied);
  20. case INSiriAuthorizationStatusAuthorized:
  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. [INPreferences requestSiriAuthorization:^(__unused INSiriAuthorizationStatus status) {
  31. [self checkWithResolver:resolve rejecter:reject];
  32. }];
  33. } else {
  34. resolve(RNPermissionStatusNotAvailable);
  35. }
  36. }
  37. @end