Skip to content

Commit

Permalink
Updated the IABTCF_TCString validator
Browse files Browse the repository at this point in the history
  • Loading branch information
Astrovic committed May 10, 2024
1 parent 368b86d commit abd1591
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 39 deletions.
73 changes: 37 additions & 36 deletions ios/Classes/TiAdmobModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -54,42 +54,43 @@ - (NSString *)moduleId
- (void)deleteTCStringIfOutdated {
NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];

// IABTCF string is stored in userDefaults
NSString *tcString = [userDefaults stringForKey:@"IABTCF_TCString"] ?: @"";

// Check if the TCF string is empty
if (tcString.length > 0) {
// Retrieve the IABTCF string from userDefaults
NSString *tcString = [userDefaults stringForKey:@"IABTCF_TCString"];

// base64 alphabet used to store data in IABTCF string
NSString *base64 = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

// Date is stored in digits 1..7 of the IABTCF string
NSString *dateSubstring = [tcString substringWithRange:NSMakeRange(1, 6)];

// Interpret date substring as base64-encoded integer value
long timestamp = 0;
for (int i = 0; i < dateSubstring.length; i++) {
unichar c = [dateSubstring characterAtIndex:i];

NSInteger value = [base64 rangeOfString:[NSString stringWithFormat:@"%C", c]].location;
timestamp = timestamp * 64 + value;
}

// Timestamp is given is deci-seconds, convert to milliseconds
timestamp *= 100;

// Compare with current timestamp to get age in days
long daysAgo = (long)(([[NSDate date] timeIntervalSince1970] * 1000) - timestamp) / (1000 * 60 * 60 * 24);
NSLog(@"[DEBUG] Ti.AdMob: TC string last updated date was %ld days ago", daysAgo);
// Delete TC string if age is over a year
if (daysAgo > 365) {
[userDefaults removeObjectForKey:@"IABTCF_TCString"];
[userDefaults synchronize];
NSLog(@"[DEBUG] Ti.AdMob: TC string removed");
}
} else {
NSLog(@"[DEBUG] The TCF string does not exist or is empty.");
}
// Return early if the TC string does not exist
if (!tcString) {
NSLog(@"[DEBUG] The IABTCF_TCString does not exist.");
return;
}

// Base64 alphabet used to store data in IABTCF string
NSString *base64 = @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";

// Date is stored in digits 1..7 of the IABTCF string
NSString *dateSubstring = [tcString substringWithRange:NSMakeRange(1, 6)];

// Interpret date substring as base64-encoded integer value
long long timestamp = 0;
for (int i = 0; i < dateSubstring.length; i++) {
unichar c = [dateSubstring characterAtIndex:i];
NSUInteger value = [base64 rangeOfString:[NSString stringWithFormat:@"%C", c]].location;
timestamp = timestamp * 64 + value;
}

// Timestamp is given in deci-seconds, convert to milliseconds
timestamp *= 100;

// Calculate age in days by comparing with the current timestamp
long daysAgo = (long)(([[NSDate date] timeIntervalSince1970] * 1000 - timestamp) / (1000 * 60 * 60 * 24));

// Delete TC string if it is over a year old
if (daysAgo > 365) {
[userDefaults removeObjectForKey:@"IABTCF_TCString"];
[userDefaults synchronize];
NSLog(@"[DEBUG] Ti.AdMob: TC string removed as it was %ld days old.", daysAgo);
} else {
NSLog(@"[DEBUG] Ti.AdMob: TC string is not outdated. Last updated %ld days ago.", daysAgo);
}
}

- (void)disableSDKCrashReporting:(id)unused
Expand Down Expand Up @@ -430,7 +431,7 @@ - (void)requestTrackingAuthorization:(id)args

- (void)setAdvertiserTrackingEnabled:(id)advertiserTrackingEnabled
{
NSLog(@"[WARN] Ti.AdMob: The setter for advertiserTrackingEnabled flag is deprecated since Ti.Admob 7.1.0: The setAdvertiserTrackingEnabled flag is not used for Audience Network SDK 6.15.0+ on iOS 17+ as the Audience Network SDK 6.15.0+ on iOS 17+ now relies on [ATTrackingManager trackingAuthorizationStatus] to accurately represent ATT permission for users of your app);");
DEPRECATED_REMOVED(@"advertiserTrackingEnabled", @"7.1.0", @"8.0.0 The setAdvertiserTrackingEnabled flag is not used for Audience Network SDK 6.15.0+ on iOS 17+ as the Audience Network SDK 6.15.0+ on iOS 17+ now relies on [ATTrackingManager trackingAuthorizationStatus] to accurately represent ATT permission for users of your app);");

// this method is required by Facebook Audience Network for iOS >= 14
if (@available(iOS 14, *)) {
Expand Down
4 changes: 2 additions & 2 deletions ios/admob.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
24DD6CF71134B3F500162E58 /* TiAdmobModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TiAdmobModule.h; path = Classes/TiAdmobModule.h; sourceTree = "<group>"; };
24DD6CF81134B3F500162E58 /* TiAdmobModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TiAdmobModule.m; path = Classes/TiAdmobModule.m; sourceTree = "<group>"; };
24DD6D1B1134B66800162E58 /* titanium.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = titanium.xcconfig; sourceTree = "<group>"; };
3ABFE38126335E0000887180 /* GoogleMobileAds.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = GoogleMobileAds.xcframework; path = platform/GoogleMobileAds.xcframework; sourceTree = "<group>"; };
3ABFE38926335E0000887180 /* UserMessagingPlatform.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = UserMessagingPlatform.xcframework; path = platform/UserMessagingPlatform.xcframework; sourceTree = "<group>"; };
3ABFE38126335E0000887180 /* GoogleMobileAds.xcframework */ = {isa = PBXFileReference; expectedSignature = "AppleDeveloperProgram:CSTR6SUWN9:AdMob, Inc."; lastKnownFileType = wrapper.xcframework; name = GoogleMobileAds.xcframework; path = platform/GoogleMobileAds.xcframework; sourceTree = "<group>"; };
3ABFE38926335E0000887180 /* UserMessagingPlatform.xcframework */ = {isa = PBXFileReference; expectedSignature = "AppleDeveloperProgram:CSTR6SUWN9:AdMob, Inc."; lastKnownFileType = wrapper.xcframework; name = UserMessagingPlatform.xcframework; path = platform/UserMessagingPlatform.xcframework; sourceTree = "<group>"; };
3AF5B7711C233383002E3DC7 /* TiAdmobTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TiAdmobTypes.h; path = Classes/TiAdmobTypes.h; sourceTree = "<group>"; };
5E0B17A327F21AED001D0BD9 /* admob-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "admob-Bridging-Header.h"; sourceTree = "<group>"; };
5E0B17A427F21AED001D0BD9 /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = "<group>"; };
Expand Down
2 changes: 1 addition & 1 deletion ios/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 7.1.0
version: 7.1.1
architectures: arm64 x86_64
mac: false
description: AdMob module for ad delivery via AdMob
Expand Down

0 comments on commit abd1591

Please sign in to comment.