From abd1591da62d2400114e61a04b8820e31c962d6f Mon Sep 17 00:00:00 2001 From: Astrovic Date: Fri, 10 May 2024 20:48:21 +0200 Subject: [PATCH] Updated the IABTCF_TCString validator --- ios/Classes/TiAdmobModule.m | 73 +++++++++++++++-------------- ios/admob.xcodeproj/project.pbxproj | 4 +- ios/manifest | 2 +- 3 files changed, 40 insertions(+), 39 deletions(-) diff --git a/ios/Classes/TiAdmobModule.m b/ios/Classes/TiAdmobModule.m index fa8ee36..2f6eb43 100644 --- a/ios/Classes/TiAdmobModule.m +++ b/ios/Classes/TiAdmobModule.m @@ -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 @@ -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, *)) { diff --git a/ios/admob.xcodeproj/project.pbxproj b/ios/admob.xcodeproj/project.pbxproj index 2626ec9..c861a82 100644 --- a/ios/admob.xcodeproj/project.pbxproj +++ b/ios/admob.xcodeproj/project.pbxproj @@ -38,8 +38,8 @@ 24DD6CF71134B3F500162E58 /* TiAdmobModule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TiAdmobModule.h; path = Classes/TiAdmobModule.h; sourceTree = ""; }; 24DD6CF81134B3F500162E58 /* TiAdmobModule.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = TiAdmobModule.m; path = Classes/TiAdmobModule.m; sourceTree = ""; }; 24DD6D1B1134B66800162E58 /* titanium.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; path = titanium.xcconfig; sourceTree = ""; }; - 3ABFE38126335E0000887180 /* GoogleMobileAds.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = GoogleMobileAds.xcframework; path = platform/GoogleMobileAds.xcframework; sourceTree = ""; }; - 3ABFE38926335E0000887180 /* UserMessagingPlatform.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = UserMessagingPlatform.xcframework; path = platform/UserMessagingPlatform.xcframework; sourceTree = ""; }; + 3ABFE38126335E0000887180 /* GoogleMobileAds.xcframework */ = {isa = PBXFileReference; expectedSignature = "AppleDeveloperProgram:CSTR6SUWN9:AdMob, Inc."; lastKnownFileType = wrapper.xcframework; name = GoogleMobileAds.xcframework; path = platform/GoogleMobileAds.xcframework; sourceTree = ""; }; + 3ABFE38926335E0000887180 /* UserMessagingPlatform.xcframework */ = {isa = PBXFileReference; expectedSignature = "AppleDeveloperProgram:CSTR6SUWN9:AdMob, Inc."; lastKnownFileType = wrapper.xcframework; name = UserMessagingPlatform.xcframework; path = platform/UserMessagingPlatform.xcframework; sourceTree = ""; }; 3AF5B7711C233383002E3DC7 /* TiAdmobTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TiAdmobTypes.h; path = Classes/TiAdmobTypes.h; sourceTree = ""; }; 5E0B17A327F21AED001D0BD9 /* admob-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "admob-Bridging-Header.h"; sourceTree = ""; }; 5E0B17A427F21AED001D0BD9 /* File.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = File.swift; sourceTree = ""; }; diff --git a/ios/manifest b/ios/manifest index 0e53713..e9af4a0 100644 --- a/ios/manifest +++ b/ios/manifest @@ -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