RNPermissionHandlerStoreKit.m 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. #import "RNPermissionHandlerStoreKit.h"
  2. @import StoreKit;
  3. @implementation RNPermissionHandlerStoreKit
  4. + (NSArray<NSString *> * _Nonnull)usageDescriptionKeys {
  5. return @[@"NSAppleMusicUsageDescription"];
  6. }
  7. + (NSString * _Nonnull)handlerUniqueId {
  8. return @"ios.permission.STOREKIT";
  9. }
  10. - (void)checkWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
  11. rejecter:(void (__unused ^ _Nonnull)(NSError * _Nonnull))reject {
  12. #if TARGET_OS_SIMULATOR
  13. return resolve(RNPermissionStatusNotAvailable);
  14. #else
  15. if (@available(iOS 9.3, *)) {
  16. switch ([SKCloudServiceController authorizationStatus]) {
  17. case SKCloudServiceAuthorizationStatusNotDetermined:
  18. return resolve(RNPermissionStatusNotDetermined);
  19. case SKCloudServiceAuthorizationStatusRestricted:
  20. return resolve(RNPermissionStatusRestricted);
  21. case SKCloudServiceAuthorizationStatusDenied:
  22. return resolve(RNPermissionStatusDenied);
  23. case SKCloudServiceAuthorizationStatusAuthorized:
  24. return resolve(RNPermissionStatusAuthorized);
  25. }
  26. } else {
  27. resolve(RNPermissionStatusNotAvailable);
  28. }
  29. #endif
  30. }
  31. - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve
  32. rejecter:(void (^ _Nonnull)(NSError * _Nonnull))reject {
  33. if (@available(iOS 9.3, *)) {
  34. [SKCloudServiceController requestAuthorization:^(__unused SKCloudServiceAuthorizationStatus status) {
  35. [self checkWithResolver:resolve rejecter:reject];
  36. }];
  37. } else {
  38. resolve(RNPermissionStatusNotAvailable);
  39. }
  40. }
  41. @end