Skip to content

Commit 7816427

Browse files
Merge pull request #400 from SourcePointUSA/dia-1573_do_not_sell_button
DIA-1537 Fix Do not sell button not working
2 parents 2457964 + 4620ea1 commit 7816427

File tree

5 files changed

+65
-49
lines changed

5 files changed

+65
-49
lines changed

ConsentViewController/Classes/SPConsentManager.swift

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ import UIKit
132132
delegate: self
133133
)
134134
controller.delegate = self
135-
controller.snapshot = CCPAPMConsentSnaptshot()
135+
controller.ccpaConsents = userData.ccpa?.consents
136136
return controller
137137
}
138138
return nil
@@ -428,7 +428,7 @@ import UIKit
428428
delegate: self
429429
)
430430
pmViewController.delegate = self
431-
// pmViewController.snapshot = CCPAPMConsentSnaptshot(withStatus: self?.userData.ccpa?.consents?.status)
431+
pmViewController.ccpaConsents = self?.userData.ccpa?.consents
432432
self?.loaded(pmViewController)
433433
case .failure(let error):
434434
self?.onError(error)

ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/CCPA/SPCCPANativePrivacyManagerViewController.swift

+55-43
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ import Foundation
2626

2727
var doNotSellButton: SPNativeLongButton?
2828

29+
var ccpaConsents: SPCCPAConsent?
30+
private var snapshot: CCPAPMConsentSnaptshot!
31+
2932
@IBOutlet weak var header: SPPMHeader!
3033

3134
var secondLayerData: CCPAPrivacyManagerViewResponse?
3235

3336
let cellReuseIdentifier = "cell"
3437

35-
var snapshot: CCPAPMConsentSnaptshot?
36-
3738
override var preferredFocusedView: UIView? { acceptButton }
3839

3940
override func setFocusGuides() {
@@ -55,8 +56,32 @@ import Foundation
5556
loaded(self)
5657
}
5758

59+
func setDoNotSellButton() {
60+
doNotSellButton = viewData.byId("DoNotSellButton") as? SPNativeLongButton
61+
doNotSellTableView.register(
62+
UINib(nibName: "LongButtonViewCell", bundle: Bundle.framework),
63+
forCellReuseIdentifier: cellReuseIdentifier
64+
)
65+
doNotSellTableView.allowsSelection = true
66+
doNotSellTableView.delegate = self
67+
doNotSellTableView.dataSource = self
68+
}
69+
70+
func initConsentsSnapshot() {
71+
snapshot = CCPAPMConsentSnaptshot(
72+
vendors: [],
73+
categories: [],
74+
rejectedVendors: ccpaConsents?.rejectedVendors,
75+
rejectedCategories: ccpaConsents?.rejectedCategories,
76+
consentStatus: ccpaConsents?.status)
77+
snapshot.onConsentsChange = { [weak self] in
78+
self?.doNotSellTableView.reloadData()
79+
}
80+
}
81+
5882
override func viewDidLoad() {
5983
super.viewDidLoad()
84+
initConsentsSnapshot()
6085
setHeader()
6186
loadTextView(forComponentId: "PublisherDescription", textView: descriptionTextView, bounces: false)
6287
descriptionTextView.flashScrollIndicators()
@@ -67,17 +92,7 @@ import Foundation
6792
loadButton(forComponentId: "NavVendorsButton", button: ourPartners)
6893
loadButton(forComponentId: "NavPrivacyPolicyButton", button: privacyPolicyButton)
6994
loadImage(forComponentId: "LogoImage", imageView: logoImageView)
70-
doNotSellButton = viewData.byId("DoNotSellButton") as? SPNativeLongButton
71-
doNotSellTableView.register(
72-
UINib(nibName: "LongButtonViewCell", bundle: Bundle.framework),
73-
forCellReuseIdentifier: cellReuseIdentifier
74-
)
75-
doNotSellTableView.allowsSelection = true
76-
doNotSellTableView.delegate = self
77-
doNotSellTableView.dataSource = self
78-
snapshot?.onConsentsChange = { [weak self] in
79-
self?.doNotSellTableView.reloadData()
80-
}
95+
setDoNotSellButton()
8196
setFocusGuidesForButtons()
8297
disableMenuButton()
8398
}
@@ -118,9 +133,19 @@ import Foundation
118133
}
119134

120135
@IBAction func onSaveAndExitTap(_ sender: Any) {
121-
let actionType: SPActionType = (snapshot?.consentStatus == .RejectedAll) ? .RejectAll : .AcceptAll
136+
var actionType: SPActionType
137+
switch snapshot.consentStatus {
138+
case .RejectedSome: actionType = .SaveAndExit
139+
case .RejectedAll: actionType = .RejectAll
140+
case .ConsentedAll, .RejectedNone: actionType = . AcceptAll
141+
}
142+
122143
action(
123-
SPAction(type: actionType, campaignType: campaignType),
144+
SPAction(
145+
type: actionType,
146+
campaignType: campaignType,
147+
pmPayload: snapshot.toPayload(language: .English, pmId: messageId).json() ?? SPJson()
148+
),
124149
from: self
125150
)
126151
}
@@ -142,15 +167,13 @@ import Foundation
142167
delegate: self,
143168
nibName: "SPCCPAManagePreferenceViewController"
144169
)
145-
if self?.snapshot == nil {
146-
self?.snapshot = CCPAPMConsentSnaptshot(
147-
vendors: Set<CCPAVendor>(data.vendors),
148-
categories: Set<CCPACategory>(data.categories),
149-
rejectedVendors: data.rejectedVendors,
150-
rejectedCategories: data.rejectedCategories,
151-
consentStatus: data.consentStatus
152-
)
153-
}
170+
self?.snapshot = CCPAPMConsentSnaptshot(
171+
vendors: Set<CCPAVendor>(data.vendors),
172+
categories: Set<CCPACategory>(data.categories),
173+
rejectedVendors: data.rejectedVendors,
174+
rejectedCategories: data.rejectedCategories,
175+
consentStatus: data.consentStatus
176+
)
154177
controller.categories = data.categories
155178
controller.consentsSnapshot = strongSelf.snapshot!
156179
self?.present(controller, animated: true)
@@ -167,15 +190,6 @@ import Foundation
167190
delegate: self,
168191
nibName: "SPManagePreferenceViewController"
169192
)
170-
if snapshot == nil {
171-
snapshot = CCPAPMConsentSnaptshot(
172-
vendors: Set<CCPAVendor>(secondLayerData.vendors),
173-
categories: Set<CCPACategory>(secondLayerData.categories),
174-
rejectedVendors: secondLayerData.rejectedVendors,
175-
rejectedCategories: secondLayerData.rejectedCategories,
176-
consentStatus: secondLayerData.consentStatus
177-
)
178-
}
179193
controller.categories = secondLayerData.categories
180194
controller.consentsSnapshot = snapshot!
181195
present(controller, animated: true)
@@ -188,14 +202,12 @@ import Foundation
188202
self?.onError(error)
189203
case .success(let data):
190204
if let strongSelf = self {
191-
if self?.snapshot == nil {
192-
self?.snapshot = CCPAPMConsentSnaptshot(
193-
vendors: Set<CCPAVendor>(data.vendors),
194-
categories: Set<CCPACategory>(data.categories),
195-
rejectedVendors: data.rejectedVendors,
196-
rejectedCategories: data.rejectedCategories, consentStatus: data.consentStatus
197-
)
198-
}
205+
self?.snapshot = CCPAPMConsentSnaptshot(
206+
vendors: Set<CCPAVendor>(data.vendors),
207+
categories: Set<CCPACategory>(data.categories),
208+
rejectedVendors: data.rejectedVendors,
209+
rejectedCategories: data.rejectedCategories, consentStatus: data.consentStatus
210+
)
199211
let controller = SPCCPAPartnersViewController(
200212
messageId: strongSelf.messageId,
201213
campaignType: strongSelf.campaignType,
@@ -267,7 +279,7 @@ extension SPCCPANativePrivacyManagerViewController: UITableViewDataSource {
267279
cell.labelText = doNotSellButton?.settings.text
268280
cell.selectable = false
269281
cell.isCustom = false
270-
cell.isOn = snapshot?.consentStatus == .RejectedAll
282+
cell.isOn = snapshot.consentStatus == .RejectedAll
271283
cell.setup(from: doNotSellButton)
272284
cell.loadUI()
273285
return cell
@@ -285,6 +297,6 @@ extension SPCCPANativePrivacyManagerViewController: UITableViewDelegate {
285297
}
286298

287299
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
288-
snapshot?.onDoNotSellToggle()
300+
snapshot.onDoNotSellToggle()
289301
}
290302
}

ConsentViewController/Classes/Views/tvOS/NativePrivacyManager/CCPA/SPCCPAPartnersViewController.swift

+5-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,11 @@ extension SPCCPAPartnersViewController: UITableViewDataSource, UITableViewDelega
107107

108108
let vendor = vendors[indexPath.row]
109109
cell.labelText = vendor.name
110-
cell.isOn = !consentsSnapshot.toggledVendorsIds.contains(vendor._id)
110+
switch consentsSnapshot.consentStatus {
111+
case .ConsentedAll, .RejectedNone: cell.isOn = true
112+
case .RejectedAll: cell.isOn = false
113+
case .RejectedSome: cell.isOn = !consentsSnapshot.toggledVendorsIds.contains(vendor._id)
114+
}
111115
cell.selectable = true
112116
cell.isCustom = false
113117
cell.setup(from: nativeLongButton)

Example/ConsentViewController.xcworkspace/xcshareddata/swiftpm/Package.resolved

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"kind" : "remoteSourceControl",
66
"location" : "http://github.com/SourcePointUSA/ios-cmp-app.git",
77
"state" : {
8-
"revision" : "7f145c21be033ad5cc9d608ab60344b2bc7f2bd3",
9-
"version" : "6.7.2-pre.1"
8+
"revision" : "a393158541f331fe6f2ec460246ee5f59df45fae",
9+
"version" : "6.7.2"
1010
}
1111
}
1212
],

Example/NativePMExampleApp/ViewController.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ViewController: UIViewController {
2020
}
2121

2222
@IBAction func onCCPATap(_ sender: Any) {
23-
consentManager.loadCCPAPrivacyManager(withId: "713327")
23+
consentManager.loadCCPAPrivacyManager(withId: "750805")
2424
}
2525

2626
lazy var consentManager: SPConsentManager = { SPConsentManager(

0 commit comments

Comments
 (0)