From 583dcda817c643a1fb9713d059a5fcceccdd6e27 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Thu, 21 Mar 2019 10:15:42 +0000 Subject: [PATCH 1/8] refactor userContentController --- .../Classes/ConsentViewController.swift | 89 ++++++++++--------- 1 file changed, 49 insertions(+), 40 deletions(-) diff --git a/ConsentViewController/Classes/ConsentViewController.swift b/ConsentViewController/Classes/ConsentViewController.swift index 62862326a..266c68cdc 100644 --- a/ConsentViewController/Classes/ConsentViewController.swift +++ b/ConsentViewController/Classes/ConsentViewController.swift @@ -406,39 +406,51 @@ import Reachability } userDefaults.setValue(String(parsedPurposeConsents), forKey: ConsentViewController.IAB_CONSENT_PARSED_PURPOSE_CONSENTS) } + + private func onReceiveMessage(willShow: Bool) { + if(willShow) { + webView.frame = webView.superview!.bounds + willShowMessage?(self) + } else { done() } + } - private func isDefined(_ string: String) -> Bool { - return string != "undefined" + private func onMessageChoiceSelect(choiceType: Int) { + guard Reachability()!.connection != .none else { + onErrorOccurred?(NoInternetConnection()) + done() + return + } + self.choiceType = choiceType + onMessageChoiceSelect?(self) } - /// :nodoc: - public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { - guard - let messageBody = message.body as? [String: Any], - let name = messageBody["name"] as? String, - let body = messageBody["body"] as? [String: Any?] - else { return } + private func onInteractionComplete(euconsent: String, consentUUID: String) { + self.euconsent = euconsent + self.consentUUID = consentUUID + do { + try storeIABVars(euconsent) + let userDefaults = UserDefaults.standard + userDefaults.setValue(euconsent, forKey: ConsentViewController.EU_CONSENT_KEY) + userDefaults.setValue(consentUUID, forKey: ConsentViewController.CONSENT_UUID_KEY) + userDefaults.synchronize() + } catch let error as ConsentViewControllerError { + onErrorOccurred?(error) + } catch {} + done() + } + private func onErrorOccurred(errorType: String) { + onErrorOccurred?(WebViewErrors[errorType] ?? PrivacyManagerUnknownError()) + done() + } + + private func handleMessage(withName name: String, andBody body: [String:Any?]) { switch name { case "onReceiveMessageData": // when the message is first loaded - if(body["willShowMessage"] as! Int) == 1 { - webView.frame = webView.superview!.bounds - willShowMessage?(self) - return - } - done() + onReceiveMessage(willShow: body["willShowMessage"] as! Int == 1) case "onMessageChoiceSelect": // when a choice is selected - guard let choiceType = body["choiceType"] as? Int else { return } - guard Reachability()!.connection != .none else { - onErrorOccurred?(NoInternetConnection()) - done() - return - } - self.choiceType = choiceType - onMessageChoiceSelect?(self) - + onMessageChoiceSelect(choiceType: body["choiceType"] as! Int) case "interactionComplete": // when interaction with message is complete - let userDefaults = UserDefaults.standard guard let euconsent = body["euconsent"] as? String, let consentUUID = body["consentUUID"] as? String @@ -447,28 +459,25 @@ import Reachability done() return } - - self.euconsent = euconsent - self.consentUUID = consentUUID - do { - try storeIABVars(euconsent) - userDefaults.setValue(euconsent, forKey: ConsentViewController.EU_CONSENT_KEY) - userDefaults.setValue(consentUUID, forKey: ConsentViewController.CONSENT_UUID_KEY) - userDefaults.synchronize() - } catch let error as ConsentViewControllerError { - onErrorOccurred?(error) - } catch {} - done() + onInteractionComplete(euconsent: euconsent, consentUUID: consentUUID) case "onErrorOccurred": - let errorType = body["errorType"] as? String ?? "" - onErrorOccurred?(WebViewErrors[errorType] ?? PrivacyManagerUnknownError()) - done() + onErrorOccurred(errorType: body["errorType"] as? String ?? "") default: print("userContentController was called but the message body: \(name) is unknown.") done() } } + /// :nodoc: + public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) { + guard + let messageBody = message.body as? [String: Any], + let name = messageBody["name"] as? String, + let body = messageBody["body"] as? [String: Any?] + else { return } + handleMessage(withName: name, andBody: body) + } + private func done() { onInteractionComplete?(self) webView.removeFromSuperview() From 1032d1c8e93102fe5f42d4b2f2e0fb6f5e51ae18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Thu, 21 Mar 2019 11:09:12 +0000 Subject: [PATCH 2/8] move loading message to loadMessage method --- .../Classes/ConsentViewController.swift | 31 +++--- .../ViewController.swift | 99 ++++++++----------- 2 files changed, 57 insertions(+), 73 deletions(-) diff --git a/ConsentViewController/Classes/ConsentViewController.swift b/ConsentViewController/Classes/ConsentViewController.swift index 266c68cdc..ae7c35e07 100644 --- a/ConsentViewController/Classes/ConsentViewController.swift +++ b/ConsentViewController/Classes/ConsentViewController.swift @@ -95,7 +95,7 @@ import Reachability sometimes, depending on how the scenario was set up, the message might not show at all, thus this call back won't be called. */ - public var willShowMessage: Callback? + public var onMessageReady: Callback? /** A `Callback` that will be called when the user selects an option on the WebView. @@ -258,14 +258,15 @@ import Reachability return nil } - /// :nodoc: - override open func viewDidLoad() { - super.viewDidLoad() - webView.frame = CGRect(x: 0, y: 0, width: 0, height: 0) - let messageUrl: URL + private enum MessageStatus { case notStarted, loading, loaded } + private var messageStatus = MessageStatus.notStarted + public func loadMessage() { + if(messageStatus == .loading || messageStatus == .loaded) { return } do { - messageUrl = try sourcePoint.getMessageUrl(forTargetingParams: targetingParams, debugLevel: debugLevel.rawValue) + messageStatus = .loading + loadView() + let messageUrl = try sourcePoint.getMessageUrl(forTargetingParams: targetingParams, debugLevel: debugLevel.rawValue) print ("url: \((messageUrl.absoluteString))") UserDefaults.standard.setValue(true, forKey: "IABConsent_CMPPresent") setSubjectToGDPR() @@ -274,12 +275,20 @@ import Reachability return } webView.load(URLRequest(url: messageUrl)) + messageStatus = .loaded } catch let error as ConsentViewControllerError { + messageStatus = .notStarted onErrorOccurred?(error) return } catch {} } + /// :nodoc: + override open func viewDidLoad() { + super.viewDidLoad() + loadMessage() + } + private func setSubjectToGDPR() { if(UserDefaults.standard.string(forKey: ConsentViewController.IAB_CONSENT_SUBJECT_TO_GDPR) != nil) { return } @@ -406,12 +415,9 @@ import Reachability } userDefaults.setValue(String(parsedPurposeConsents), forKey: ConsentViewController.IAB_CONSENT_PARSED_PURPOSE_CONSENTS) } - + private func onReceiveMessage(willShow: Bool) { - if(willShow) { - webView.frame = webView.superview!.bounds - willShowMessage?(self) - } else { done() } + willShow ? onMessageReady?(self) : done() } private func onMessageChoiceSelect(choiceType: Int) { @@ -480,7 +486,6 @@ import Reachability private func done() { onInteractionComplete?(self) - webView.removeFromSuperview() } } diff --git a/Example/ConsentViewController/ViewController.swift b/Example/ConsentViewController/ViewController.swift index db5f38dae..4637fdcb4 100644 --- a/Example/ConsentViewController/ViewController.swift +++ b/Example/ConsentViewController/ViewController.swift @@ -10,84 +10,63 @@ import ConsentViewController class ViewController: UIViewController { var consentViewController: ConsentViewController! - private func buildConsentViewController(showPM: Bool) throws -> ConsentViewController { - let consentViewController = try ConsentViewController( + private func buildConsentViewController(showPM: Bool, addToView parentView: UIView) { + do { + let consentViewController = try ConsentViewController( accountId: 22, siteName: "mobile.demo", stagingCampaign: false ) - // optional, set custom targeting parameters supports Strings and Integers - consentViewController.setTargetingParam(key: "CMP", value: String(showPM)) - - // optional, sets debug level defaults to OFF - consentViewController.debugLevel = ConsentViewController.DebugLevel.OFF - - consentViewController.willShowMessage = { cvc in print("the message will show") } - // optional, callback triggered when message choice is selected when called choice - // type will be available as Integer at cvc.choiceType - consentViewController.onMessageChoiceSelect = { cvc in - print("Choice type selected by user", cvc.choiceType as Any) - } - - consentViewController.onErrorOccurred = { error in print(error) } - - // optional, callback triggered when consent data is captured when called - // euconsent will be available as String at cLib.euconsent and under - // PreferenceManager.getDefaultSharedPreferences(activity).getString(EU_CONSENT_KEY, null); - // consentUUID will be available as String at cLib.consentUUID and under - // PreferenceManager.getDefaultSharedPreferences(activity).getString(CONSENT_UUID_KEY null); - consentViewController.onInteractionComplete = { cvc in - do { - print( - "\n eu consent prop", - cvc.euconsent as Any, - "\n consent uuid prop", - cvc.consentUUID as Any, - "\n eu consent in storage", - UserDefaults.standard.string(forKey: ConsentViewController.EU_CONSENT_KEY) as Any, - "\n consent uuid in storage", - UserDefaults.standard.string(forKey: ConsentViewController.CONSENT_UUID_KEY) as Any, + consentViewController.onMessageReady = { controller in + parentView.addSubview(controller.view) + controller.view.frame = controller.view.superview!.bounds + } - // Standard IAB values in UserDefaults - "\n IABConsent_ConsentString in storage", - UserDefaults.standard.string(forKey: ConsentViewController.IAB_CONSENT_CONSENT_STRING) as Any, - "\n IABConsent_ParsedPurposeConsents in storage", - UserDefaults.standard.string(forKey: ConsentViewController.IAB_CONSENT_PARSED_PURPOSE_CONSENTS) as Any, - "\n IABConsent_ParsedVendorConsents in storage", - UserDefaults.standard.string(forKey: ConsentViewController.IAB_CONSENT_PARSED_VENDOR_CONSENTS) as Any, + // optional, set custom targeting parameters supports Strings and Integers + consentViewController.setTargetingParam(key: "CMP", value: String(showPM)) - // API for getting IAB Purpose Consents - "\n IAB purpose consent for \"Ad selection, delivery, reporting\"", - try cvc.getIABPurposeConsents([3]) - ) - print("Custom vendor consents") - for consent in try cvc.getCustomVendorConsents() { - print("Custom Vendor Consent id: \(consent.id), name: \(consent.name)") - } - print("Custom purpose consents") - for consent in try cvc.getCustomPurposeConsents() { - print("Custom Purpose Consent id: \(consent.id), name: \(consent.name)") + consentViewController.onErrorOccurred = { error in print(error) } + + consentViewController.onInteractionComplete = { cvc in + do { + print( + // Standard IAB values in UserDefaults + "\n IABConsent_ConsentString in storage", + UserDefaults.standard.string(forKey: ConsentViewController.IAB_CONSENT_CONSENT_STRING) as Any, + "\n IABConsent_ParsedPurposeConsents in storage", + UserDefaults.standard.string(forKey: ConsentViewController.IAB_CONSENT_PARSED_PURPOSE_CONSENTS) as Any, + "\n IABConsent_ParsedVendorConsents in storage", + UserDefaults.standard.string(forKey: ConsentViewController.IAB_CONSENT_PARSED_VENDOR_CONSENTS) as Any, + // API for getting IAB Purpose Consents + "\n IAB purpose consent for \"Ad selection, delivery, reporting\"", + try cvc.getIABPurposeConsents([3]) + ) + print("Custom vendor consents") + for consent in try cvc.getCustomVendorConsents() { + print("Custom Vendor Consent id: \(consent.id), name: \(consent.name)") + } + print("Custom purpose consents") + for consent in try cvc.getCustomPurposeConsents() { + print("Custom Purpose Consent id: \(consent.id), name: \(consent.name)") + } } + catch { print(error) } + cvc.view.removeFromSuperview() } - catch { print(error) } - } - return consentViewController + consentViewController.loadMessage() + } catch { print(error) } } @IBAction func showPrivacyManager(_ sender: Any) { - do { - try view.addSubview(buildConsentViewController(showPM: true).view) - } catch { print(error) } + buildConsentViewController(showPM: true, addToView: view) } override func viewDidLoad() { super.viewDidLoad() - do { - try view.addSubview(buildConsentViewController(showPM: false).view) - } catch { print(error) } + buildConsentViewController(showPM: false, addToView: view) // IABConsent_CMPPresent must be set immediately after loading the ConsentViewController print( From 32145399c420f03b0ee14e2f2543150a2519a6bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Wed, 27 Mar 2019 16:06:07 +0100 Subject: [PATCH 3/8] let getGdprStatus throw --- .../Classes/ConsentViewController.swift | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/ConsentViewController/Classes/ConsentViewController.swift b/ConsentViewController/Classes/ConsentViewController.swift index ae7c35e07..a47ad58e7 100644 --- a/ConsentViewController/Classes/ConsentViewController.swift +++ b/ConsentViewController/Classes/ConsentViewController.swift @@ -269,7 +269,7 @@ import Reachability let messageUrl = try sourcePoint.getMessageUrl(forTargetingParams: targetingParams, debugLevel: debugLevel.rawValue) print ("url: \((messageUrl.absoluteString))") UserDefaults.standard.setValue(true, forKey: "IABConsent_CMPPresent") - setSubjectToGDPR() + try setSubjectToGDPR() guard Reachability()!.connection != .none else { onErrorOccurred?(NoInternetConnection()) return @@ -289,15 +289,10 @@ import Reachability loadMessage() } - private func setSubjectToGDPR() { + private func setSubjectToGDPR() throws { if(UserDefaults.standard.string(forKey: ConsentViewController.IAB_CONSENT_SUBJECT_TO_GDPR) != nil) { return } - - do { - let gdprStatus = try sourcePoint.getGdprStatus() - UserDefaults.standard.setValue(String(gdprStatus), forKey: ConsentViewController.IAB_CONSENT_SUBJECT_TO_GDPR) - } catch { - print(error) - } + let gdprStatus = try sourcePoint.getGdprStatus() + UserDefaults.standard.setValue(String(gdprStatus), forKey: ConsentViewController.IAB_CONSENT_SUBJECT_TO_GDPR) } /** From a84c7850e94e7fbc127706822d6f7bec9352ea5e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Wed, 27 Mar 2019 16:06:44 +0100 Subject: [PATCH 4/8] reset messageStatus to notStarted if internet connection is none --- ConsentViewController/Classes/ConsentViewController.swift | 1 + 1 file changed, 1 insertion(+) diff --git a/ConsentViewController/Classes/ConsentViewController.swift b/ConsentViewController/Classes/ConsentViewController.swift index a47ad58e7..703fa7225 100644 --- a/ConsentViewController/Classes/ConsentViewController.swift +++ b/ConsentViewController/Classes/ConsentViewController.swift @@ -272,6 +272,7 @@ import Reachability try setSubjectToGDPR() guard Reachability()!.connection != .none else { onErrorOccurred?(NoInternetConnection()) + messageStatus = .notStarted return } webView.load(URLRequest(url: messageUrl)) From 2ff3d71789b8b131f6e2e60c748655aa35090f4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Wed, 27 Mar 2019 16:27:26 +0100 Subject: [PATCH 5/8] safe guard message body on handleMessage --- .../Classes/ConsentViewController.swift | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/ConsentViewController/Classes/ConsentViewController.swift b/ConsentViewController/Classes/ConsentViewController.swift index 703fa7225..3a70a5efb 100644 --- a/ConsentViewController/Classes/ConsentViewController.swift +++ b/ConsentViewController/Classes/ConsentViewController.swift @@ -449,23 +449,21 @@ import Reachability private func handleMessage(withName name: String, andBody body: [String:Any?]) { switch name { case "onReceiveMessageData": // when the message is first loaded - onReceiveMessage(willShow: body["willShowMessage"] as! Int == 1) + guard let willShow = body["willShowMessage"] as? Int else { fallthrough } + onReceiveMessage(willShow: willShow == 1) case "onMessageChoiceSelect": // when a choice is selected - onMessageChoiceSelect(choiceType: body["choiceType"] as! Int) + guard let choiceType = body["choiceType"] as? Int else { fallthrough } + onMessageChoiceSelect(choiceType: choiceType) case "interactionComplete": // when interaction with message is complete guard let euconsent = body["euconsent"] as? String, let consentUUID = body["consentUUID"] as? String - else { - print("Could not get EUConsent and ConsentUUID") - done() - return - } + else { fallthrough } onInteractionComplete(euconsent: euconsent, consentUUID: consentUUID) case "onErrorOccurred": onErrorOccurred(errorType: body["errorType"] as? String ?? "") default: - print("userContentController was called but the message body: \(name) is unknown.") + print("Couldn't parse message in userContentController. Called with name: \(name) and body: \(body)") done() } } From 900316148d205ecd8afa9ef2fef5a44eb5f6015c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Wed, 27 Mar 2019 16:32:52 +0100 Subject: [PATCH 6/8] Update ViewController.swift --- Example/ConsentViewController/ViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Example/ConsentViewController/ViewController.swift b/Example/ConsentViewController/ViewController.swift index 4637fdcb4..b45232989 100644 --- a/Example/ConsentViewController/ViewController.swift +++ b/Example/ConsentViewController/ViewController.swift @@ -20,7 +20,7 @@ class ViewController: UIViewController { consentViewController.onMessageReady = { controller in parentView.addSubview(controller.view) - controller.view.frame = controller.view.superview!.bounds + controller.view.frame = parentView.bounds } // optional, set custom targeting parameters supports Strings and Integers From b61c6a306ebb794afa67a2fac592af3e975bb888 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Fri, 29 Mar 2019 11:02:56 +0100 Subject: [PATCH 7/8] implement PrivacyManagerUnknownMessageResponse --- .../Classes/ConsentViewControllerError.swift | 38 ++++++++++++------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/ConsentViewController/Classes/ConsentViewControllerError.swift b/ConsentViewController/Classes/ConsentViewControllerError.swift index aaf101a8c..1e1da545b 100644 --- a/ConsentViewController/Classes/ConsentViewControllerError.swift +++ b/ConsentViewController/Classes/ConsentViewControllerError.swift @@ -16,7 +16,7 @@ public struct UnableToParseConsentStringError: ConsentViewControllerError { public var errorDescription: String? { get { return "Could not parse the raw string \(euConsent) into a ConsentString" } } init(euConsent: String) { self.euConsent = euConsent } - public var description: String { get {return "\(failureReason!)\n\(errorDescription!)" } } + public var description: String { get { return "\(failureReason!)\n\(errorDescription!)" } } } public struct InvalidMessageURLError: ConsentViewControllerError { @@ -27,12 +27,11 @@ public struct InvalidMessageURLError: ConsentViewControllerError { public var helpAnchor: String? { get { return "Please make sure the query params are URL encodable." } } init(urlString: String) { self.urlString = urlString } - public var description: String { get {return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } + public var description: String { get { return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } } public struct InvalidURLError: ConsentViewControllerError { - private let urlName: String - private let urlString: String + private let urlName: String, urlString: String public var failureReason: String? { get { return "Failed to parse \(urlName)." } } public var errorDescription: String? { get { return "Could not convert \(urlString) into URL." } } @@ -42,12 +41,11 @@ public struct InvalidURLError: ConsentViewControllerError { self.urlName = urlName self.urlString = urlString } - public var description: String { get {return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } + public var description: String { get { return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } } public struct SiteIDNotFound: ConsentViewControllerError { - private let accountId: String - private let siteName: String + private let accountId: String, siteName: String public var failureReason: String? { get { return "Could not find site ID)." } } public var errorDescription: String? { get { return "Could not find a site with name \(siteName) for the account id \(accountId)" } } @@ -57,7 +55,7 @@ public struct SiteIDNotFound: ConsentViewControllerError { self.accountId = accountId self.siteName = siteName } - public var description: String { get {return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } + public var description: String { get { return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } } public struct GdprStatusNotFound: ConsentViewControllerError { @@ -67,13 +65,13 @@ public struct GdprStatusNotFound: ConsentViewControllerError { public var helpAnchor: String? { get { return "Make sure \(gdprStatusUrl) is correct." } } init(gdprStatusUrl: URL) { self.gdprStatusUrl = gdprStatusUrl } - public var description: String { get {return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } + public var description: String { get { return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } } public struct ConsentsAPIError: ConsentViewControllerError { public var failureReason: String? { get { return "Failed to get Custom Consents" } } public var errorDescription: String? { get { return "Failed to either get custom consents or parse the endpoint's response" } } - public var description: String { get {return "\(failureReason!)\n\(errorDescription!)" } } + public var description: String { get { return "\(failureReason!)\n\(errorDescription!)" } } } public let WebViewErrors: [String : ConsentViewControllerError] = [ @@ -85,22 +83,34 @@ public struct PrivacyManagerLoadError: ConsentViewControllerError { public var failureReason: String? { get { return "Failed start the Privacy Manager" } } public var errorDescription: String? { get { return "Could not load the Privacy Manager due to a javascript error." } } public var helpAnchor: String? { get { return "This is most probably happening due to a misconfiguration on the Publisher's portal." } } - public var description: String { get {return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } + public var description: String { get { return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } } public struct PrivacyManagerSaveError: ConsentViewControllerError { public var failureReason: String? { get { return "Failed to save user consents on Privacy Manager" } } public var errorDescription: String? { get { return "Something wrong happened while saving the privacy settings on the Privacy Manager" } } public var helpAnchor: String? { get { return "This might have occurred due to faulty internet connection." } } - public var description: String { get {return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } + public var description: String { get { return "\(failureReason!)\n\(errorDescription!)\n\(helpAnchor!)" } } +} + +public struct PrivacyManagerUnknownMessageResponse: ConsentViewControllerError { + private let name: String, body: [String:Any?] + init(name: String, body: [String:Any?]) { + self.name = name + self.body = body + } + public var failureReason: String? { get { + return "Couldn't parse message in userContentController. Called with name: \(name) and body: \(body)" + }} + public var description: String { get { return "\(failureReason!)\n" } } } public struct PrivacyManagerUnknownError: ConsentViewControllerError { public var failureReason: String? { get { return "Something bad happened in the javascript world." } } - public var description: String { get {return "\(failureReason!)\n" } } + public var description: String { get { return "\(failureReason!)\n" } } } public struct NoInternetConnection: ConsentViewControllerError { public var failureReason: String? { get { return "The device is not connected to the internet." } } - public var description: String { get {return "\(failureReason!)\n" } } + public var description: String { get { return "\(failureReason!)\n" } } } From 1f871f980188235e7a40323455da2d5f89d25121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Herculano?= Date: Fri, 29 Mar 2019 11:03:35 +0100 Subject: [PATCH 8/8] call onErrorOccurred with PrivacyManagerUnknownMessageResponse by default on handleMessage --- .../Classes/ConsentViewController.swift | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/ConsentViewController/Classes/ConsentViewController.swift b/ConsentViewController/Classes/ConsentViewController.swift index 3a70a5efb..67dcd0a77 100644 --- a/ConsentViewController/Classes/ConsentViewController.swift +++ b/ConsentViewController/Classes/ConsentViewController.swift @@ -441,8 +441,8 @@ import Reachability done() } - private func onErrorOccurred(errorType: String) { - onErrorOccurred?(WebViewErrors[errorType] ?? PrivacyManagerUnknownError()) + private func onErrorOccurred(_ error: ConsentViewControllerError) { + onErrorOccurred?(error) done() } @@ -461,10 +461,9 @@ import Reachability else { fallthrough } onInteractionComplete(euconsent: euconsent, consentUUID: consentUUID) case "onErrorOccurred": - onErrorOccurred(errorType: body["errorType"] as? String ?? "") + onErrorOccurred(WebViewErrors[body["errorType"] as? String ?? ""] ?? PrivacyManagerUnknownError()) default: - print("Couldn't parse message in userContentController. Called with name: \(name) and body: \(body)") - done() + onErrorOccurred(PrivacyManagerUnknownMessageResponse(name: name, body: body)) } } @@ -474,7 +473,10 @@ import Reachability let messageBody = message.body as? [String: Any], let name = messageBody["name"] as? String, let body = messageBody["body"] as? [String: Any?] - else { return } + else { + onErrorOccurred(PrivacyManagerUnknownMessageResponse(name: "", body: ["":""])) + return + } handleMessage(withName: name, andBody: body) }