Skip to content
This repository was archived by the owner on Apr 16, 2024. It is now read-only.

Commit 0e57859

Browse files
store local data when getting the message as well as reporting an action
* consentUUID * ccpaApplies * userConsents
1 parent ee1af5c commit 0e57859

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

CCPAConsentViewController/Classes/CCPAConsentViewController.swift

+15-11
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ public typealias TargetingParams = [String: String]
181181
sourcePoint.getMessage(consentUUID: consentUUID, authId: authId) { [weak self] messageResponse, error in
182182
self?.loading = .Ready
183183
if let message = messageResponse {
184+
self?.setLocalStorageData(uuid: message.uuid, userConsent: message.userConsent, ccpaApplies: message.ccpaApplies)
184185
self?.consentUUID = message.uuid
185-
CCPAConsentViewController.setCCPAApplies(message.ccpaApplies)
186-
CCPAConsentViewController.setUSPrivacyString(message.userConsent.uspstring)
186+
self?.userConsent = message.userConsent
187187
if let url = message.url {
188188
self?.loadMessage(fromUrl: url)
189189
} else {
@@ -196,6 +196,16 @@ public typealias TargetingParams = [String: String]
196196
}
197197
}
198198

199+
func setLocalStorageData(uuid: ConsentUUID, userConsent: UserConsent, ccpaApplies: Bool) {
200+
UserDefaults.standard.set(uuid, forKey: CCPAConsentViewController.CONSENT_UUID_KEY)
201+
CCPAConsentViewController.setUSPrivacyString(userConsent.uspstring)
202+
CCPAConsentViewController.setCCPAApplies(ccpaApplies)
203+
if let encodedConsents = try? JSONEncoder().encode(userConsent) {
204+
UserDefaults.standard.set(String(data: encodedConsents, encoding: .utf8), forKey: CCPAConsentViewController.CCPA_USER_CONSENTS)
205+
}
206+
UserDefaults.standard.synchronize()
207+
}
208+
199209
func didAuthIdChange(newAuthId: String?) -> Bool {
200210
let storedAuthId = UserDefaults.standard.string(forKey: CCPAConsentViewController.CCPA_AUTH_ID_KEY)
201211
return newAuthId != nil && storedAuthId != nil && storedAuthId != newAuthId
@@ -259,8 +269,9 @@ extension CCPAConsentViewController: ConsentDelegate {
259269
if action == .AcceptAll || action == .RejectAll || action == .SaveAndExit {
260270
sourcePoint.postAction(action: action, consentUUID: consentUUID, consents: consents) { [weak self] actionResponse, error in
261271
if let response = actionResponse {
262-
CCPAConsentViewController.setUSPrivacyString(response.userConsent.uspstring)
263-
CCPAConsentViewController.setCCPAApplies(response.ccpaApplies)
272+
self?.consentUUID = response.uuid
273+
self?.userConsent = response.userConsent
274+
self?.setLocalStorageData(uuid: response.uuid, userConsent: response.userConsent, ccpaApplies: response.ccpaApplies)
264275
self?.onConsentReady(consentUUID: response.uuid, userConsent: response.userConsent)
265276
} else {
266277
self?.onError(error: error)
@@ -270,13 +281,6 @@ extension CCPAConsentViewController: ConsentDelegate {
270281
}
271282

272283
public func onConsentReady(consentUUID: ConsentUUID, userConsent: UserConsent) {
273-
self.consentUUID = consentUUID
274-
self.userConsent = userConsent
275-
if let encodedConsents = try? JSONEncoder().encode(userConsent) {
276-
UserDefaults.standard.set(String(data: encodedConsents, encoding: .utf8), forKey: CCPAConsentViewController.CCPA_USER_CONSENTS)
277-
}
278-
UserDefaults.standard.set(consentUUID, forKey: CCPAConsentViewController.CONSENT_UUID_KEY)
279-
UserDefaults.standard.synchronize()
280284
consentDelegate?.onConsentReady?(consentUUID: consentUUID, userConsent: userConsent)
281285
}
282286

0 commit comments

Comments
 (0)