| 
3 | 3 | @import AppTrackingTransparency;  | 
4 | 4 | @import AdSupport;  | 
5 | 5 | 
 
  | 
 | 6 | +@interface RNPermissionHandlerAppTrackingTransparency()  | 
 | 7 | + | 
 | 8 | +@property (nonatomic, strong) void (^resolve)(RNPermissionStatus status);  | 
 | 9 | +@property (nonatomic, strong) void (^reject)(NSError *error);  | 
 | 10 | + | 
 | 11 | +@end  | 
 | 12 | + | 
6 | 13 | @implementation RNPermissionHandlerAppTrackingTransparency  | 
7 | 14 | 
 
  | 
8 | 15 | + (NSArray<NSString *> * _Nonnull)usageDescriptionKeys {  | 
@@ -38,12 +45,38 @@ - (void)checkWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve  | 
38 | 45 | - (void)requestWithResolver:(void (^ _Nonnull)(RNPermissionStatus))resolve  | 
39 | 46 |                    rejecter:(void (^ _Nonnull)(NSError * _Nonnull))reject {  | 
40 | 47 |   if (@available(iOS 14.0, *)) {  | 
41 |  | -    [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(__unused ATTrackingManagerAuthorizationStatus status) {  | 
42 |  | -      [self checkWithResolver:resolve rejecter:reject];  | 
43 |  | -    }];  | 
 | 48 | +    if ([ATTrackingManager trackingAuthorizationStatus] != ATTrackingManagerAuthorizationStatusNotDetermined) {  | 
 | 49 | +      return [self checkWithResolver:resolve rejecter:reject];  | 
 | 50 | +    }  | 
 | 51 | + | 
 | 52 | +    if ([[UIApplication sharedApplication] applicationState] == UIApplicationStateActive) {  | 
 | 53 | +      [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(__unused ATTrackingManagerAuthorizationStatus status) {  | 
 | 54 | +        [self checkWithResolver:resolve rejecter:reject];  | 
 | 55 | +      }];  | 
 | 56 | +    } else {  | 
 | 57 | +      _resolve = resolve;  | 
 | 58 | +      _reject = reject;  | 
 | 59 | + | 
 | 60 | +      [[NSNotificationCenter defaultCenter] addObserver:self  | 
 | 61 | +                                               selector:@selector(onApplicationDidBecomeActive:)  | 
 | 62 | +                                                   name:UIApplicationDidBecomeActiveNotification  | 
 | 63 | +                                                 object:nil];  | 
 | 64 | +    }  | 
44 | 65 |   } else {  | 
45 | 66 |     [self checkWithResolver:resolve rejecter:reject];  | 
46 | 67 |   }  | 
47 | 68 | }  | 
48 | 69 | 
 
  | 
 | 70 | +- (void)onApplicationDidBecomeActive:(__unused NSNotification *)notification {  | 
 | 71 | +  [[NSNotificationCenter defaultCenter] removeObserver:self  | 
 | 72 | +                                                  name:UIApplicationDidBecomeActiveNotification  | 
 | 73 | +                                                object:nil];  | 
 | 74 | + | 
 | 75 | +  if (@available(iOS 14.0, *)) {  | 
 | 76 | +    [ATTrackingManager requestTrackingAuthorizationWithCompletionHandler:^(__unused ATTrackingManagerAuthorizationStatus status) {  | 
 | 77 | +      [self checkWithResolver:self->_resolve rejecter:self->_reject];  | 
 | 78 | +    }];  | 
 | 79 | +  }  | 
 | 80 | +}  | 
 | 81 | + | 
49 | 82 | @end  | 
0 commit comments