Skip to content

Commit 91135b9

Browse files
Updated preloadConsentDataScript() method, fixed crash. Project version updated to 1.0.11-rc.
1 parent 70adf74 commit 91135b9

4 files changed

Lines changed: 57 additions & 11 deletions

File tree

ClickioConsentSDKManager.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Pod::Spec.new do |spec|
66

77
spec.module_name = "ClickioConsentSDKManager"
88

9-
spec.version = "1.0.10"
9+
spec.version = "1.0.11-rc"
1010

1111
spec.summary = "Native SDK for managing user consents, integrating a WebView-based consent dialog into iOS apps for streamlined privacy compliance."
1212

ClickioConsentSDKManager.xcodeproj/project.pbxproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@
353353
"@executable_path/Frameworks",
354354
"@loader_path/Frameworks",
355355
);
356-
MARKETING_VERSION = 1.0.10;
356+
MARKETING_VERSION = "1.0.11-rc";
357357
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
358358
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
359359
PRODUCT_BUNDLE_IDENTIFIER = com.ClickioConsentSDKManager;
@@ -394,7 +394,7 @@
394394
"@executable_path/Frameworks",
395395
"@loader_path/Frameworks",
396396
);
397-
MARKETING_VERSION = 1.0.10;
397+
MARKETING_VERSION = "1.0.11-rc";
398398
MODULE_VERIFIER_SUPPORTED_LANGUAGES = "objective-c objective-c++";
399399
MODULE_VERIFIER_SUPPORTED_LANGUAGE_STANDARDS = "gnu17 gnu++20";
400400
PRODUCT_BUNDLE_IDENTIFIER = com.ClickioConsentSDKManager;
@@ -468,7 +468,7 @@
468468
INFOPLIST_KEY_NSUserTrackingUsageDescription = "This app collects and tracks your usage data for the purpose of delivering personalized advertisements and measuring ad performance. By using this app, you acknowledge and agree that your information may be processed and shared with our advertising partners.";
469469
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
470470
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
471-
MARKETING_VERSION = 1.0.10;
471+
MARKETING_VERSION = "1.0.11-rc";
472472
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
473473
MTL_FAST_MATH = YES;
474474
ONLY_ACTIVE_ARCH = YES;
@@ -530,7 +530,7 @@
530530
INFOPLIST_KEY_NSUserTrackingUsageDescription = "This app collects and tracks your usage data for the purpose of delivering personalized advertisements and measuring ad performance. By using this app, you acknowledge and agree that your information may be processed and shared with our advertising partners.";
531531
IPHONEOS_DEPLOYMENT_TARGET = 15.6;
532532
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
533-
MARKETING_VERSION = 1.0.10;
533+
MARKETING_VERSION = "1.0.11-rc";
534534
MTL_ENABLE_DEBUG_INFO = NO;
535535
MTL_FAST_MATH = YES;
536536
SDKROOT = iphoneos;

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Before integrating `ClickioConsentSDKManager` (hereinafter reffered to as the `C
2020
**Swift Package Manager**
2121
- File > Swift Packages > Add Package Dependency
2222
- Add `https://github.com/ClickioTech/ClickioConsentSDK-IOS.git`
23-
- Select "Up to Next Major" with "1.0.10"
23+
- Select "Up to Next Major" with "1.0.11-rc"
2424

2525
**CocoaPods**
2626
- You can install ClickioConsentSDKManager pod from CocoaPods library:
@@ -29,7 +29,7 @@ platform :ios, '15.0'
2929
use_frameworks!
3030
3131
target 'YourApp' do
32-
pod 'ClickioConsentSDKManager', '~> 1.0.10'
32+
pod 'ClickioConsentSDKManager', '~> 1.0.11-rc'
3333
end
3434
```
3535

@@ -39,7 +39,7 @@ platform :ios, '15.0'
3939
use_frameworks!
4040
4141
target 'YourApp' do
42-
pod 'ClickioConsentSDKManager', :git => 'https://github.com/ClickioTech/ClickioConsentSDK-IOS.git', :tag => '1.0.10'
42+
pod 'ClickioConsentSDKManager', :git => 'https://github.com/ClickioTech/ClickioConsentSDK-IOS.git', :tag => '1.0.11-rc'
4343
end
4444
```
4545

Sources/WebView/WebViewController/WebViewController.swift

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,61 @@ public final class WebViewController: UIViewController {
160160
}
161161

162162
func preloadConsentDataScript() -> String {
163+
func makeJSONCompatible(_ any: Any) -> Any? {
164+
if let s = any as? String { return s }
165+
if let n = any as? NSNumber { return n }
166+
if any is NSNull { return NSNull() }
167+
168+
if let data = any as? Data {
169+
return data.base64EncodedString()
170+
}
171+
if let url = any as? URL {
172+
return url.absoluteString
173+
}
174+
if let date = any as? Date {
175+
return ISO8601DateFormatter().string(from: date)
176+
}
177+
if let arr = any as? [Any] {
178+
return arr.compactMap { makeJSONCompatible($0) }
179+
}
180+
if let dict = any as? [String: Any] {
181+
var out = [String: Any]()
182+
for (k, v) in dict {
183+
if let vv = makeJSONCompatible(v) {
184+
out[k] = vv
185+
}
186+
}
187+
return out
188+
}
189+
return String(describing: any)
190+
}
191+
163192
let defaults = UserDefaults.standard
164-
let storedValues = defaults.dictionaryRepresentation()
165-
let jsonData = try! JSONSerialization.data(withJSONObject: storedValues, options: [])
193+
let all = defaults.dictionaryRepresentation()
194+
195+
var safe = [String: Any]()
196+
for (k, v) in all {
197+
if let converted = makeJSONCompatible(v) {
198+
safe[k] = converted
199+
}
200+
}
201+
202+
let jsonData: Data
203+
do {
204+
if !JSONSerialization.isValidJSONObject(safe) {
205+
throw NSError(domain: "JSON", code: 1, userInfo: [NSLocalizedDescriptionKey: "Not a valid JSON object"])
206+
}
207+
jsonData = try JSONSerialization.data(withJSONObject: safe, options: [])
208+
} catch {
209+
logger.log("Failed to create JSON for preload: \(error.localizedDescription)", level: .error)
210+
jsonData = "{}".data(using: .utf8)!
211+
}
212+
166213
let jsonString = String(data: jsonData, encoding: .utf8) ?? "{}"
167214

168215
return """
169216
(function() {
170217
window.clickioSDK = window.clickioSDK || {};
171-
172218
window.clickioSDK.preloaded = \(jsonString);
173219
174220
const originalWrite = window.clickioSDK.write;

0 commit comments

Comments
 (0)