|
39 | 39 | #import "NSString+Branch.h" |
40 | 40 | #import "BNCSpotlightService.h" |
41 | 41 | #import "../Fabric/FABKitProtocol.h" // Fabric |
| 42 | +#import <stdatomic.h> |
42 | 43 |
|
43 | 44 | NSString * const BRANCH_FEATURE_TAG_SHARE = @"share"; |
44 | 45 | NSString * const BRANCH_FEATURE_TAG_REFERRAL = @"referral"; |
|
76 | 77 | #define CSSearchableItemActivityIdentifier @"kCSSearchableItemActivityIdentifier" |
77 | 78 | #endif |
78 | 79 |
|
| 80 | +static inline dispatch_time_t BNCDispatchTimeFromSeconds(NSTimeInterval seconds) { |
| 81 | + return dispatch_time(DISPATCH_TIME_NOW, seconds * NSEC_PER_SEC); |
| 82 | +} |
| 83 | + |
| 84 | +static inline void BNCAfterSecondsPerformBlock(NSTimeInterval seconds, dispatch_block_t block) { |
| 85 | + dispatch_after(BNCDispatchTimeFromSeconds(seconds), dispatch_get_main_queue(), block); |
| 86 | +} |
| 87 | + |
79 | 88 | #pragma mark - Load Categories |
80 | 89 |
|
81 | 90 | void ForceCategoriesToLoad(void); |
@@ -881,8 +890,12 @@ - (BOOL)checkAppleSearchAdsAttribution { |
881 | 890 | self.preferenceHelper.checkedAppleSearchAdAttribution = YES; |
882 | 891 | self.asyncRequestCount++; |
883 | 892 |
|
| 893 | + _Atomic __block BOOL hasBeenCalled = NO; |
884 | 894 | void (^__nullable completionBlock)(NSDictionary *attrDetails, NSError *error) = |
885 | 895 | ^ void(NSDictionary *__nullable attrDetails, NSError *__nullable error) { |
| 896 | + BOOL localHasBeenCalled = atomic_exchange(&hasBeenCalled, YES); |
| 897 | + if (localHasBeenCalled) return; |
| 898 | + |
886 | 899 | self.asyncRequestCount--; |
887 | 900 |
|
888 | 901 | // If searchAdsDebugMode is on then force the result to a set value for testing: |
@@ -929,6 +942,11 @@ - (BOOL)checkAppleSearchAdsAttribution { |
929 | 942 | }); |
930 | 943 | }; |
931 | 944 |
|
| 945 | + // Set a expiration timer in case we don't get a call back (I'm looking at you, iPad): |
| 946 | + BNCAfterSecondsPerformBlock(10.0, ^ { |
| 947 | + completionBlock(nil, [NSError errorWithDomain:NSNetServicesErrorDomain code:NSNetServicesTimeoutError userInfo:nil]); |
| 948 | + }); |
| 949 | + |
932 | 950 | ((void (*)(id, SEL, void (^ __nullable)(NSDictionary *__nullable attrDetails, NSError * __nullable error))) |
933 | 951 | [sharedClientInstance methodForSelector:requestAttribution]) |
934 | 952 | (sharedClientInstance, requestAttribution, completionBlock); |
|
0 commit comments