@ququplay/admob 7.0.2 → 7.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -63,6 +63,44 @@ public class AdConsentExecutor extends Executor {
63
63
  );
64
64
  }
65
65
 
66
+ public boolean isConsentOutdated() {
67
+ Context context = contextSupplier.get();
68
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
69
+ String tcString = prefs.getString("IABTCF_TCString", "");
70
+
71
+ if (tcString == null || tcString.isEmpty()) {
72
+ return false;
73
+ }
74
+
75
+ // base64 alphabet used to store data in IABTCF string
76
+ String base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
77
+
78
+ // date is stored in digits 1..7 of the IABTCF string
79
+ String dateSubstring = tcString.substring(1, 7);
80
+
81
+ // interpret date substring as base64-encoded integer value
82
+ long timestamp = 0L;
83
+
84
+ for (char c : dateSubstring.toCharArray()) {
85
+ int value = base64.indexOf(c);
86
+ timestamp = timestamp * 64 + value;
87
+ }
88
+
89
+ // timestamp is given in deci-seconds, convert to milliseconds
90
+ timestamp *= 100;
91
+
92
+ // compare with current timestamp to get age in days
93
+ long daysAgo = (System.currentTimeMillis() - timestamp) / (1000 * 60 * 60 * 24);
94
+
95
+ // delete TC string if age is over a year
96
+ if (daysAgo > 365) {
97
+ prefs.edit().remove("IABTCF_TCString").apply();
98
+ return true;
99
+ }
100
+
101
+ return false;
102
+ }
103
+
66
104
  public boolean canShowAds() {
67
105
  Context context = contextSupplier.get();
68
106
  SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext());
@@ -132,6 +170,7 @@ public class AdConsentExecutor extends Executor {
132
170
  consentInfo.put("isConsentFormAvailable", consentInformation.isConsentFormAvailable());
133
171
  consentInfo.put("canShowAds", canShowAds());
134
172
  consentInfo.put("canShowPersonalizedAds", canShowPersonalizedAds());
173
+ consentInfo.put("isConsentOutdated", isConsentOutdated());
135
174
  call.resolve(consentInfo);
136
175
  },
137
176
  formError -> call.reject(formError.getMessage())
@@ -163,6 +202,7 @@ public class AdConsentExecutor extends Executor {
163
202
  consentFormInfo.put("status", getConsentStatusString(consentInformation.getConsentStatus()));
164
203
  consentFormInfo.put("canShowAds", canShowAds());
165
204
  consentFormInfo.put("canShowPersonalizedAds", canShowPersonalizedAds());
205
+ consentFormInfo.put("isConsentOutdated", isConsentOutdated());
166
206
  call.resolve(consentFormInfo);
167
207
  }
168
208
  }),
@@ -27,7 +27,8 @@ class ConsentExecutor: NSObject {
27
27
  "status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus),
28
28
  "isConsentFormAvailable": UMPConsentInformation.sharedInstance.formStatus == UMPFormStatus.available,
29
29
  "canShowAds": self.canShowAds(),
30
- "canShowPersonalizedAds": self.canShowPersonalizedAds()
30
+ "canShowPersonalizedAds": self.canShowPersonalizedAds(),
31
+ "isConsentOutdated": self.isConsentOutdated()
31
32
  ])
32
33
  }
33
34
  })
@@ -53,7 +54,8 @@ class ConsentExecutor: NSObject {
53
54
  call.resolve([
54
55
  "status": self.getConsentStatusString(UMPConsentInformation.sharedInstance.consentStatus),
55
56
  "canShowAds": self.canShowAds(),
56
- "canShowPersonalizedAds": self.canShowPersonalizedAds()
57
+ "canShowPersonalizedAds": self.canShowPersonalizedAds(),
58
+ "isConsentOutdated": self.isConsentOutdated()
57
59
  ])
58
60
  })
59
61
  })
@@ -147,4 +149,40 @@ class ConsentExecutor: NSObject {
147
149
  return hasConsentFor([1,3,4], purposeConsent, hasGoogleVendorConsent)
148
150
  && hasConsentOrLegitimateInterestFor([2,7,9,10], purposeConsent, purposeLI, hasGoogleVendorConsent, hasGoogleVendorLI)
149
151
  }
152
+
153
+ private func isConsentOutdated() -> Bool {
154
+ let settings = UserDefaults.standard
155
+ guard let tcString = settings.string(forKey: "IABTCF_TCString"), !tcString.isEmpty else {
156
+ return false
157
+ }
158
+
159
+ // base64 alphabet used to store data in IABTCF string
160
+ let base64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_"
161
+
162
+ // date is stored in digits 1..7 of the IABTCF string
163
+ let dateSubstring = String(tcString[tcString.index(tcString.startIndex, offsetBy: 1)..<tcString.index(tcString.startIndex, offsetBy: 7)])
164
+
165
+ // interpret date substring as base64-encoded integer value
166
+ var timestamp: Int64 = 0
167
+
168
+ for char in dateSubstring {
169
+ if let value = base64.firstIndex(of: char) {
170
+ timestamp = timestamp * 64 + Int64(value.utf16Offset(in: base64))
171
+ }
172
+ }
173
+
174
+ // timestamp is given in deci-seconds, convert to milliseconds
175
+ timestamp *= 100
176
+
177
+ // compare with current timestamp to get age in days
178
+ let daysAgo = (Int64(Date().timeIntervalSince1970 * 1000) - timestamp) / (1000 * 60 * 60 * 24)
179
+
180
+ // delete TC string if age is over a year
181
+ if daysAgo > 365 {
182
+ settings.removeObject(forKey: "IABTCF_TCString")
183
+ return true
184
+ }
185
+
186
+ return false
187
+ }
150
188
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ququplay/admob",
3
- "version": "7.0.2",
3
+ "version": "7.0.3",
4
4
  "description": "A native plugin for AdMob",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",