Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SP-7045] Add configurable timeout #301

Merged
merged 2 commits into from
Jun 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion ConsentViewController/Classes/SPConsentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Foundation
public var userData: SPUserData { storage.userData }
var messageControllersStack: [SPMessageViewController] = []
var idfaStatus: SPIDFAStatus { SPIDFAStatus.current() }
static let DefaultTimeout = TimeInterval(30)

var ccpaUUID: String { storage.localState["ccpa"]?.dictionaryValue?["uuid"] as? String ?? "" }
var gdprUUID: String { storage.localState["gdpr"]?.dictionaryValue?["uuid"] as? String ?? "" }
Expand All @@ -35,13 +36,20 @@ import Foundation
SPUserDefaults(storage: UserDefaults.standard).clear()
}

/// The timeout interval in seconds for the message being displayed
public var messageTimeoutInSeconds = SPConsentManager.DefaultTimeout {
didSet {
spClient.setRequestTimeout(self.messageTimeoutInSeconds)
}
}

public convenience init(accountId: Int, propertyName: SPPropertyName, campaigns: SPCampaigns, delegate: SPDelegate?) {
self.init(
accountId: accountId,
propertyName: propertyName,
campaigns: campaigns,
delegate: delegate,
spClient: SourcePointClient(accountId: accountId, propertyName: propertyName, timeout: 30),
spClient: SourcePointClient(accountId: accountId, propertyName: propertyName, timeout: SPConsentManager.DefaultTimeout),
storage: SPUserDefaults(storage: UserDefaults.standard)
)
}
Expand Down Expand Up @@ -101,6 +109,7 @@ import Foundation
messageId: messageId,
contents: content,
campaignType: type,
timeout: messageTimeoutInSeconds,
delegate: self
)
#endif
Expand Down Expand Up @@ -278,6 +287,7 @@ import Foundation
messageId: messageId,
contents: SPJson(),
campaignType: campaignType,
timeout: messageTimeoutInSeconds,
delegate: self
).loadPrivacyManager(url: pmURL)
}
Expand Down
4 changes: 3 additions & 1 deletion ConsentViewController/Classes/SPMessageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ extension RenderingAppEvents: ExpressibleByStringLiteral {
weak var messageUIDelegate: SPMessageUIDelegate?
public var campaignType: SPCampaignType
public var messageId: Int?
public var timeout: TimeInterval

init(messageId: Int?, campaignType: SPCampaignType, delegate: SPMessageUIDelegate?, nibName: String? = nil) {
init(messageId: Int?, campaignType: SPCampaignType, timeout: TimeInterval, delegate: SPMessageUIDelegate?, nibName: String? = nil) {
self.campaignType = campaignType
self.messageUIDelegate = delegate
self.messageId = messageId
self.timeout = timeout
super.init(nibName: nibName, bundle: Bundle.framework)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import Foundation
import WebKit

@objcMembers class SPWebMessageViewController: SPMessageViewController, WKUIDelegate, WKNavigationDelegate, WKScriptMessageHandler, UIScrollViewDelegate {
var timeout: TimeInterval?
var webviewConfig: WKWebViewConfiguration? { nil }
let url: URL
let contents: SPJson
Expand All @@ -35,10 +34,10 @@ import WebKit
return nil
}()

init(url: URL, messageId: Int?, contents: SPJson, campaignType: SPCampaignType, delegate: SPMessageUIDelegate?) {
init(url: URL, messageId: Int?, contents: SPJson, campaignType: SPCampaignType, timeout: TimeInterval, delegate: SPMessageUIDelegate?) {
self.url = url
self.contents = contents
super.init(messageId: messageId, campaignType: campaignType, delegate: delegate)
super.init(messageId: messageId, campaignType: campaignType, timeout: timeout, delegate: delegate)
}

required init?(coder: NSCoder) {
Expand Down Expand Up @@ -134,11 +133,11 @@ import WebKit
var isFirstLayerMessage = true

override func loadMessage() {
webview?.load(URLRequest(url: url))
webview?.load(URLRequest(url: url, timeoutInterval: timeout))
}

override func loadPrivacyManager(url: URL) {
webview?.load(URLRequest(url: url))
webview?.load(URLRequest(url: url, timeoutInterval: timeout))
}

override func closePrivacyManager() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class SPErrorSpec: QuickSpec {

describe("ConnectionTimeOutError") {
it("has spCode: connection_timeout") {
expect(ConnectionTimeOutError(url: nil, timeout: nil).spCode).to(equal("sp_metric_connection_timeout"))
expect(ConnectionTimeOutError(url: nil, timeout: nil, campaignType: .unknown).spCode).to(equal("sp_metric_connection_timeout"))
}
}

Expand Down