|
9 | 9 | #import "UIDevice+AIAdditions.h"
|
10 | 10 | #import "NSString+AIAdditions.h"
|
11 | 11 |
|
12 |
| -#import <AdSupport/ASIdentifierManager.h> |
13 | 12 | #import <sys/socket.h>
|
14 | 13 | #import <sys/sysctl.h>
|
15 | 14 | #import <net/if.h>
|
16 | 15 | #import <net/if_dl.h>
|
17 | 16 |
|
| 17 | +#if !ADJUST_NO_IDFA |
| 18 | +#import <AdSupport/ASIdentifierManager.h> |
| 19 | +#endif |
| 20 | + |
18 | 21 | @implementation UIDevice(AIAdditions)
|
19 | 22 |
|
20 | 23 | - (BOOL)aiTrackingEnabled {
|
21 |
| - if (NSClassFromString(@"ASIdentifierManager")) { |
22 |
| - return ASIdentifierManager.sharedManager.advertisingTrackingEnabled; |
23 |
| - } else { |
| 24 | +#if !ADJUST_NO_IDFA |
| 25 | + NSString *className = [NSString aiJoin:@"A", @"S", @"identifier", @"manager", nil]; |
| 26 | + NSString *keyManager = [NSString aiJoin:@"shared", @"manager", nil]; |
| 27 | + NSString *keyEnabled = [NSString aiJoin:@"is", @"advertising", @"tracking", @"enabled", nil]; |
| 28 | + |
| 29 | + Class class = NSClassFromString(className); |
| 30 | + if (class) { |
| 31 | + @try { |
| 32 | + SEL selManager = NSSelectorFromString(keyManager); |
| 33 | + SEL selEnabled = NSSelectorFromString(keyEnabled); |
| 34 | + |
| 35 | +#pragma clang diagnostic push |
| 36 | +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" |
| 37 | + id manager = [class performSelector:selManager]; |
| 38 | + BOOL enabled = (BOOL)[manager performSelector:selEnabled]; |
| 39 | +#pragma clang diagnostic pop |
| 40 | + |
| 41 | + return enabled; |
| 42 | + } @catch (NSException *e) { |
| 43 | + return NO; |
| 44 | + } |
| 45 | + } else |
| 46 | +#endif |
| 47 | + { |
24 | 48 | return NO;
|
25 | 49 | }
|
26 | 50 | }
|
27 | 51 |
|
28 | 52 | - (NSString *)aiIdForAdvertisers {
|
29 |
| - if (NSClassFromString(@"ASIdentifierManager")) { |
30 |
| - return ASIdentifierManager.sharedManager.advertisingIdentifier.UUIDString; |
31 |
| - } else { |
| 53 | +#if !ADJUST_NO_IDFA |
| 54 | + NSString *className = [NSString aiJoin:@"A", @"S", @"identifier", @"manager", nil]; |
| 55 | + NSString *keyManager = [NSString aiJoin:@"shared", @"manager", nil]; |
| 56 | + NSString *keyIdentifier = [NSString aiJoin:@"advertising", @"identifier", nil]; |
| 57 | + NSString *keyString = [NSString aiJoin:@"UUID", @"string", nil]; |
| 58 | + |
| 59 | + Class class = NSClassFromString(className); |
| 60 | + if (class) { |
| 61 | + @try { |
| 62 | + SEL selManager = NSSelectorFromString(keyManager); |
| 63 | + SEL selIdentifier = NSSelectorFromString(keyIdentifier); |
| 64 | + SEL selString = NSSelectorFromString(keyString); |
| 65 | + |
| 66 | +#pragma clang diagnostic push |
| 67 | +#pragma clang diagnostic ignored "-Warc-performSelector-leaks" |
| 68 | + id manager = [class performSelector:selManager]; |
| 69 | + id identifier = [manager performSelector:selIdentifier]; |
| 70 | + NSString *string = [identifier performSelector:selString]; |
| 71 | +#pragma clang diagnostic pop |
| 72 | + |
| 73 | + return string; |
| 74 | + } @catch (NSException *e) { |
| 75 | + return @""; |
| 76 | + } |
| 77 | + } else |
| 78 | +#endif |
| 79 | + { |
32 | 80 | return @"";
|
33 | 81 | }
|
34 | 82 | }
|
@@ -101,4 +149,13 @@ - (NSString *)aiDeviceName {
|
101 | 149 | return machine;
|
102 | 150 | }
|
103 | 151 |
|
| 152 | +- (NSString *)aiCreateUuid { |
| 153 | + CFUUIDRef newUniqueId = CFUUIDCreate(kCFAllocatorDefault); |
| 154 | + CFStringRef stringRef = CFUUIDCreateString(kCFAllocatorDefault, newUniqueId); |
| 155 | + NSString *uuidString = (__bridge_transfer NSString*)stringRef; |
| 156 | + NSString *lowerUuid = [uuidString lowercaseString]; |
| 157 | + CFRelease(newUniqueId); |
| 158 | + return lowerUuid; |
| 159 | +} |
| 160 | + |
104 | 161 | @end
|
0 commit comments