Skip to content

Commit c8960f8

Browse files
implement internalOnAction and internalOnError on iOS
1 parent cfe727a commit c8960f8

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

android/src/main/java/com/sourcepoint/reactnativecmp/ReactNativeCmpModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ class ReactNativeCmpModule(reactContext: ReactApplicationContext) : NativeReactN
140140
vendors: ReadableArray,
141141
categories: ReadableArray,
142142
legIntCategories: ReadableArray,
143-
callback: Callback)
144-
{
143+
callback: Callback
144+
) {
145145
runOnMainThread {
146146
spConsentLib?.deleteCustomConsentTo(
147147
vendors.toList(),

example/ios/Podfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,4 +1996,4 @@ SPEC CHECKSUMS:
19961996

19971997
PODFILE CHECKSUM: decdc7519d77aa5eae65b167fa59bcfce25e15d2
19981998

1999-
COCOAPODS: 1.15.2
1999+
COCOAPODS: 1.16.2

ios/RNSourcepointCmp.swift

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,18 @@ import React
2828
self.customActionId = customActionId
2929
}
3030

31-
@objc public func toDictionary() -> [String: Any] {
31+
func toDictionary() -> [String: Any] {
3232
["actionType": type.description, "customActionId": customActionId]
3333
}
34+
35+
@objc public func stringifiedJson() -> String {
36+
if let jsonData = try? JSONSerialization.data(withJSONObject: toDictionary()),
37+
let jsonString = String(data: jsonData, encoding: .utf8) {
38+
return jsonString
39+
} else {
40+
return "{\"actionType:\"unknown\"}"
41+
}
42+
}
3443
}
3544

3645
@objc public protocol ReactNativeCmpImplDelegate {

ios/ReactNativeCmp.mm

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,14 @@ - (void)postDeleteCustomConsentGDPR:(NSArray *)vendors
130130

131131
// MARK: SPDelegate
132132
- (void)onAction:(RNAction*)action {
133-
[self emitOnAction: [action toDictionary]];
133+
[self emitInternalOnAction: [action stringifiedJson]];
134134
}
135135

136136
- (void)onErrorWithDescription:(NSString * _Nonnull)description {
137-
[self emitOnError: @{ @"description": description }];
137+
NSDictionary *dict = @{@"description": description};
138+
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:0 error:nil];
139+
NSString *json = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
140+
[self emitInternalOnError: json];
138141
}
139142

140143
- (void)onFinished {

0 commit comments

Comments
 (0)